JavaScript ES6 - Cheat Sheet
JavaScript ES6 - Cheat Sheet
print() // prints 5
print(22) // prints 22
console.log(a) // prints 3
console.log(a); // 3
console.log(b); // 7
Destructuring object object property assignement
let obj = { const a = 2
a: 55, const b = 5
b: 44
}; const obj = { a, b }
Object.assign() Object.entries()
const obj1 = { a: 1 } const obj = {
const obj2 = { b: 2 } firstName: 'Vipul',
lastName: 'Rawat',
const obj3 = Object.assign({}, obj1, obj2) age: 22,
country: 'India',
console.log(obj3) // { a: 1, b: 2 } };
console.log(entries);
/* prints
[
['firstName', 'Vipul'],
['lastName', 'Rawat'],
['age', 22],
['country', 'India']
];
*/
spread operator Destructuring Nested Objects
const a = { const Person = {
firstName: "Barry", name: "John Snow",
lastName: "Manilow", age: 29,
} sex: "male",
materialStatus: "single",
const b = { address: {
...a, country: "Westeros",
lastName: "White", state: "The Crownlands",
canSing: true, city: "Kings Landing",
} pinCode: "500014",
},
console.log(a) // {firstName: "Barry", lastName: };
"Manilow"}
const { address : { state, pinCode }, name } =
console.log(b) // {firstName: "Barry", lastName: Person;
"White", canSing: true}
console.log(name, state, pinCode) // John Snow
// great for modifying objects without side The Crownlands 500014
effects/affecting the original console.log(city) // ReferenceError