Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 23, 2019 15:41
Show Gist options
  • Save NyaGarcia/d284de4a5c37a20cc0bbb98713d0c8c3 to your computer and use it in GitHub Desktop.
Save NyaGarcia/d284de4a5c37a20cc0bbb98713d0c8c3 to your computer and use it in GitHub Desktop.
An example showcasing the use of the rest parameter
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
printPokemon('Squirtle', 'Water', 'Torrent', 'Rain Dish');
//Squirtle is a Water type Pokemon. Squirtle's abilities are: Torrent, Rain Dish
printPokemon('Squirtle', 'Water', 'Torrent', 'Rain Dish', 'Surf', 'Secret Ability', 'And so on...');
//Squirtle is a Water type Pokemon. Squirtle's abilities are: Torrent, Rain Dish, Surf, Secret Ability, And so on...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment