Spread Operator
const boo = [1, 2]
const foo = [3, 4]
const zoo = [...boo, ...foo]
console.log(zoo)
// prints [ 1, 2, 3, 4]
Arrow Function
const arrow = (a, b) => a + b
console.log(arrow(2, 10))
// prints 12
Function with Default Parameters
function fundef(a = 10) {
console.log(a)
}
fundef() // prints 10
fundef(29) // prints 29
Template literals (Template strings)
const word1 = 'Hello'
const word2 = `${word1} World`
console.log(word2)
// prints "Hello World"
String includes()
console.log('orange'.includes('ge')); // prints true
console.log('orange'.includes('zz')); // prints false
String repeat()
console.log('ab'.repeat(4))
// prints "abababab"
String startsWith()
console.log('orange'.includes('or')); // prints true;
console.log('orange'.includes('ge')); // prints false;
Destructing Array
let [a, b] = [1, 2]
console.log(a); // prints 1
console.log(b); // prints 2
Destructing Object
let obj = {
a1: 10,
b2: 20
};
let { a1, b2 } = obj;
console.log(a1); // prints 10
console.log(b2); // prints 20
Object.assign()
const obj1 = { q: 12 }
const obj2 = { a: 33 }
const obj3 = Object.assign({}, obj1, obj2)
console.log(obj3); // prints { q:12, a: 33 }
Destructuring Nested Objects
const item = {
device: "iPadPro",
brand: "apple",
year: 2020,
accessories: {
pencil: "2ndGen",
charger: "30W",
}
}
const { accessories: { pencil, charger }, device } = item
console.log(device, pencil, charger);
// prints "iPadPro 2ndGen 30W"
Spread Operator
const v1 = {
firstName: "Web",
lastName: "Developer"
}
const v2 = {
...v1,
lastName: "Tips",
sex: "NA"
}
console.log(v1);
// prints { firstName: 'Web', lastName: 'Developer' }
console.log(v2);
// prints { firstName: 'Web', lastName: 'Tips', sex: 'NA' }
Top comments (0)