Created
May 14, 2018 09:03
-
-
Save okjodom/7a6d0c1d80d01e406cab0de9f8bf92c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Because everybody loves a blue Subaru */ | |
// Normal parameter defaults | |
function favoriteCar(car = 'Subaru', color = 'blue') { | |
return `Everybody loves a ${color} ${car}!`; | |
} | |
console.log(favoriteCar()); // Everyody loves a blue Subaru! | |
// Parameter defaults with object destructuring | |
function favoriteCar({car = 'Subaru', color = 'blue'} = {}) { | |
return `Everybody loves a ${color} ${car}!`; | |
} | |
console.log(favoriteCar()); // Everyody loves a blue Subaru! | |
// Parameter defaults with list destructuring | |
function favoriteCar([car = 'Subaru', color = 'blue'] = []) { | |
return `Everybody loves a ${color} ${car}!`; | |
} | |
// Skipping an index in list destructured defaults | |
console.log(favoriteCar([, 'white'])); // Everyody loves a white Subary! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment