This file contains hidden or 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
const pokemon = { | |
name: 'Squirtle', | |
type: 'Water' | |
}; | |
const { abilities = [], ...rest } = pokemon; | |
const fullSquirtle = { ...rest, abilities }; | |
console.log(rest); //Result: { name: 'Squirtle', type: 'Water' } | |
console.log({ fullSquirtle }); //Result: { name: 'Squirtle', type: 'Water', abilities: [] } |
This file contains hidden or 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
function printPokemon(name, type, ...abilities) { | |
console.log( | |
`${name} is a ${type} type Pokemon. ${name}'s abilities are: ${abilities.join( | |
', ' | |
)}` | |
); | |
} | |
printPokemon('Squirtle', 'Water', 'Torrent'); | |
//Squirtle is a Water type Pokemon. Squirtle's abilities are: Torrent |
OlderNewer