Skip to content

Instantly share code, notes, and snippets.

@nodlAndHodl
Created June 1, 2018 21:34
Show Gist options
  • Save nodlAndHodl/01cf07e51a4270315b6a68749c774188 to your computer and use it in GitHub Desktop.
Save nodlAndHodl/01cf07e51a4270315b6a68749c774188 to your computer and use it in GitHub Desktop.
Spread Operator in ES6
let doWork = function(x, y, z){
return x + y + z;
}
//using the ... syntax on an array we are able to pass in the params as follows:
nums = [1, 2, 3]
let result = doWork(...nums)
//which is the equivelent as
let other_result = doWork(1,2,3);
//spread can also be used to build arrays
//example
let a = [1,3,5]
let b = [2,3, ...a,4]
console.log(b); //b is equal to [2,3,1,3,5,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment