- Top-Level Await (ES13) In ES13, await can now be used at the top level in modules, allowing for cleaner asynchronous code without wrapping it inside an async function.
// index.mjs
const data = await fetch('https://api.example.com').then(res => res.json());
console.log(data);
Why it matters in interviews: This feature simplifies working with asynchronous code in modules and helps reduce boilerplate in modern applications.
Logical Nullish Assignment (??=)(ES12)
This is part of the logical assignment operators discussed above. The ??= operator only assigns the right-hand value if the left-hand value is null or undefined.
///////
Logical Nullish Assignment (??=)(ES12)
This is part of the logical assignment operators discussed above. The ??= operator only assigns the right-hand value if the left-hand value is null or undefined.
let x = null;
let y = 5;
x ??= y;
console.log(x); // 5 (because x was null)
let z = 0;
z ??= 10;
console.log(z); // 0 (because z was not null or undefined)
This is helpful when you want to set a default value only if the variable is null or undefined.
Top comments (0)