Created
July 11, 2017 16:54
-
-
Save prof3ssorSt3v3/b84689c539ed923f7154f11372319936 to your computer and use it in GitHub Desktop.
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
//SPREAD and REST operators | |
//Added with ES6 | |
// ... | |
// two sides of the same operation | |
let beers = ['Corona', 'Heineken']; | |
let stuff = [22, 'Bob', true, beers]; | |
//SPREAD - expands an array into its elements | |
myFunc( ...stuff ); | |
function myFunc(age, name, isStudent, beerList){ | |
console.log(name, 'is', age, '\n'); | |
let b = ['Tuborg', ...beerList, 'Freedom 35']; | |
b.forEach( (item, index) => console.log(index, item) ); | |
} | |
//REST - collects multiple elements and condenses them into a single element | |
function myOtherFunc(age, name, ...list){ | |
console.log(name, 'is', age); | |
list.forEach( (item, index) => console.log( index, item) ); | |
} | |
myOtherFunc(38, 'Hank', beers, 'some text', stuff); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment