ECMAScript 2018

The JavaScript naming convention started with ES1, ES2, ES3, ES5, and ES6.

However, ECMAScript 2016 and 2017 were not called ES7 and ES8.

Since 2016, new versions have been named by year (ECMAScript 2016/2017/2018).

New features in ECMAScript 2018

This chapter introduces the new features of ECMAScript 2018:

  • Asynchronous iteration
  • Promise Finally
  • object Rest properties
  • new RegExp features

JavaScript asynchronous iteration

ECMAScript 2018 added asynchronous iterators and iterable objects.

Through asynchronous iteration, we can for/of in loops await keyword.

Instance

for await () {}

Firefox and Safari are the first browsers to support JavaScript asynchronous iteration:

Chrome IE Firefox Safari Opera
Chrome 63 Edge 79 Firefox 57 Safari 11 Opera 50
December 2017 January 2020 November 2017 September 2017 January 2018

JavaScript Promise.finally

ECMAScript 2018 uses Promise.finally Completed the full implementation of the Promise object:

Instance

let myPromise = new Promise();
myPromise.then();
myPromise.catch();
myPromise.finally();

Chrome and Firefox are the first to support Promise.finally browsers:

Chrome IE Firefox Safari Opera
Chrome 63 Edge 18 Firefox 58 Safari 11.1 Opera 50
December 2017 November 2018 January 2018 March 2018 January 2018

JavaScript object Rest property

ECMAScript 2018 added the Rest property.

This allows us to destruct an object and collect the remainder into a new object:

Instance

let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
x; // 1
y; // 2
z; // { a: 3, b: 4 }

Chrome, Firefox, and Opera are the first browsers to support the object Rest properties:

Chrome IE Firefox Safari Opera
Chrome 60 Edge 79 Firefox 55 Safari 11.1 Opera 47
July 2017 January 2020 August 2017 March 2018 August 2017

New JavaScript RegExp Features

ECMAScript 2018 added 4 new RegExp features:

  • Unicode Property Escapes (\p{...})
  • Lookbehind Assertions (?<= ) and (?<! )
  • Named Capture Groups
  • s (dotAll) flag

Chrome and Firefox were the first browsers to support all new RegExp features:

Chrome IE Firefox Safari Opera
Chrome 64 Edge 79 Firefox 78 Safari 12 Opera 51
January 2018 January 2020 June 2020 September 2018 February 2018