Last active
March 8, 2017 14:37
-
-
Save iuliaL/df85b6f6eeda1e2732c1b9cf52bf2fd5 to your computer and use it in GitHub Desktop.
Rest Parameters and Spread Operator
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
'use strict'; | |
function myFunction (name, iceCreamFlavor) { | |
console.log(`${name} really likes ${iceCreamFlavor} ice cream.`) | |
} | |
const flavours = [ 'Banana', 'Lemon'] | |
const lovedFlavours = [ "Straciatella", ...flavours] // this is the same as .concat() | |
const args = ['Iulia', lovedFlavours ]; | |
myFunction(...args); //rest parameter | |
// Iulia really likes Straciatella,Banana,Lemon ice cream. | |
// more spread + rest | |
let arr = ['jesus', 'iulia', 'dan','hilary']; | |
const func = (...args) => { // args is a rest parameter | |
console.log(...args); // -> jesus iulia dan hilary | |
console.log(''+ args[0] + args[1]+ args[2]+args[3] ); //-> jesusiuliadanhilary | |
}; | |
func(...arr); // here i spread the array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment