You are on page 1of 1

Spread

ES6 JavaScript Copy an array with spread


const newArray = [. . .oldArray1, . . .oldArray2];

CHEAT SHEET 01
Copy an object with spread
const newObject = {. . .oldObject1, . . .oldObject2};

Template literals Destructuring


Simple template literal
Destructuring assignment
“hello I’,m a template literal.”
const [first, last] = [ , ]; 'Bucky' 'Barnes'

Embed variables
Default values
const name = “Captain America”;
const scores = [22 , 23];
`Hello my name is ` ${name} ;
const [Java = 50 , JS = 50 , CPP = 50] = scores;

Embed expression
Destructuring function arguments
const isRaining = true ;
function greet({ firstname, lastname}) {
`Hey is it raining? ${isRaining ? “Yes it’s
console.log(’${firstname}${lastname}!’)
raining” : “Nope”} ;
}

Default function arguments value


Readable large integers function greet({ firstname, lastname = “smith”}) {

Old way console.log(’${firstname}${lastname}!’)

const largeNumber = 10000000; }

New Way Object destructuring


const largeNumber = 1_00_00_000; // more readable const { firstname, lastname } = user;

You might also like