Earlier ECMAScript versions were named by numbers, such as ES5 and ES6. Starting in 2016, versions are named by the year of release, like ES2016, ES2018, ES2020, and so on.
This chapter covers the new features introduced in ECMAScript 2018:
ECMAScript 2018 introduced asynchronous iterators and iterables. With asynchronous iterables, the await keyword can be used inside for/of loops.
for await () {} |
JavaScript asynchronous iteration has been supported in all modern browsers since January 2020.
ECMAScript 2018 completes the full implementation of the Promise object with the addition of Promise.finally().
let myPromise = new Promise(); myPromise.then(); myPromise.catch(); myPromise.finally(); |
Promise.finally() has been supported in all modern browsers since November 2018.
ECMAScript 2018 introduced rest properties, allowing us to destructure an object and collect the remaining properties into a new object.
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; x; // 1 y; // 2 z; // { a: 3, b: 4 } |
Object rest properties have been supported in all modern browsers since January 2020.
ECMAScript 2018 introduced four new RegExp features:
These new RegExp features have been supported in all modern browsers since June 2020.