let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y); // 2
console.log(z); // { a: 3, b: 4 }
Text
WeakMaps help developers avoid memory leaks by holding references to their properties weakly, meaning that if a WeakMap is the only object with a reference to another object, the GC may collect the referenced object.
By definition, WeakSet has only three key functionalities
WeakSet objects are collections of objects. An object in the WeakSet may occur only once; it is unique in the WeakSet's collection.
The main differences to the Set object are:
Map, forEach
arr.forEach((num, index) => {
return arr[index] = num * 2;
});// arr = [2, 4, 6, 8, 10]
let doubled = arr.map(num => {
return num * 2;
});
// doubled = [2, 4, 6, 8, 10]let arr = ['a','b','c'];
arr.findIndex(k => k=='b');
// 1arr.findIndex(k => k=='z');
// -1
if(arr.findIndex(k => k=='z') > 0)
let arr = [2, 4, 6, 8, 9, 10, 12];
function isOdd(i) {
return i % 2 !== 0;
}
arr.findIndex(isOdd);
// 4let arr = ['a','b','c'];
arr.find(k => k=='b');
// 'b'function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
var result = await resolveAfter2Seconds();
console.log(result);
// expected output: 'resolved'
}
asyncCall();
Promises, async
Bind