Professional Documents
Culture Documents
ES2021
ES2021
//"Or Or Equals"
x ||= y;
x || (x = y);
// "QQ Equals"
x ??= y;
x ?? (x = y);
const updateID = user => {
// We can do this
if (!user.id) user.id = 1
// Or this
user.id = user.id || 1
Numeric Separators
Visual separation between groups of digits
Promise.any([
fetch('https://v8.dev/').then(() => 'home'),
fetch('https://v8.dev/blog').then(() => 'blog'),
fetch('https://v8.dev/docs').then(() => 'docs')
]).then((first) => {
// Any of the promises was fulfilled.
console.log(first);
// → 'home'
}).catch((error) => {
// All of the promises were rejected.
console.log(error);
});
^ In the above example error is an AggregateError
String.prototype.replaceAll
replaceAll
// String.prototype.replaceAll(searchValue, replaceValue)
'x'.replace('', '_');
// → '_x'
'xxx'.replace(/(?:)/g, '_');
// → '_x_x_x_'
'xxx'.replaceAll('', '_');
// → '_x_x_x_'