Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spread/Rest operator
// Spread operator
function fruits(apples, bananas, pears){
console.log(apples);
console.log(bananas);
console.log(pears);
}
fruitsNo = [7, 9, 14];
fruits(...fruitsNo);
/*
7
9
14
*/
// Rest operator
function getFruitsByBasket(apples, bananas, pears) {
var fruits = [...arguments];
var howMany = fruits.map(function (fruit){
return fruit;
});
console.log(`In baskets, there are ${howMany} fruits.`)
}
getFruitsByBasket(6, 7, 8); // In baskets, there are 6,7,8 fruits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.