ECMAScript 2018
JavaScript Version Numbers
Previous versions of ECMAScript were identified using numbers: ES5 and ES6.
Starting in 2016, the versions have been named according to the year they were released: ES2016, 2018, 2020, and so on.
New Features in ECMAScript 2018
This section presents the latest additions in ECMAScript 2018.
- Asynchronous Iteration
- Promise Finally
- Object Rest Properties
- New RegExp Features
- JavaScript Shared Memory
JavaScript Asynchronous Iteration
In 2018, ECMAScript introduced asynchronous iterators and iterables.
We can use the await
keyword in for/of
loops when working with asynchronous iterables.
Example
for await () {}
JavaScript Promise.finally
ECMAScript 2018 completes the full implementation of the Promise object by introducing Promise.finally
.
Example
let myPromise = new Promise();
myPromise.then();
myPromise.catch();
myPromise.finally();
JavaScript Object Rest Properties
Rest properties were introduced in ECMAScript 2018.
We can break down an object and gather the remaining parts into a fresh object using this process:
Example
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
x; // 1
y; // 2
z; // { a: 3, b: 4 }
New JavaScript RegExp Features
ECMAScript 2018 introduced four new features for RegExp:
- Special Codes for Unicode Properties (\p{...})
- Behind-looking conditions like (?<= ) and (?
- Capture Groups with Names
- The "s (dotAll) Flag"
JavaScript Threads
You can use the Web Workers API in JavaScript to make threads.
We use worker threads to run code in the background, allowing the main program to keep running without interruptions.
Worker threads work at the same time as the main program. Doing different parts of a program simultaneously can save time.
JavaScript Shared Memory
Shared memory lets different parts of a program, known as threads, use and change data stored in the same memory location.
Instead of transferring information between threads, you can use a SharedArrayBuffer object that directs to the memory holding the data.
SharedArrayBuffer
A SharedArrayBuffer is like an ArrayBuffer but specifically for holding a fixed amount of raw binary data.