ES2017 a.k.a. ES8 is the version of ECMAScript corresponding to the year 2017. This version does not include as many new features as those that appeared in ES6 (2015). However, some useful features have been incorporated.
This article introduces the features provided by ES2017 in easy code examples. In this way, you can quickly understand the new features without the need for a complex explanation.
- ️️ String padding
- Trailing commas in function parameter lists and calls
- Async functions
- Shared memory and atomics
Object values take an object and return an array with the values, in the same order as a
for…in loop would give us.
On the other hand,
Object.entries takes an object and returns an array with arrays of key-value pairs.
padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string.
padEnd() method pads the current string with a given string
(repeated, if needed) so that the resulting string reaches
a given length.
getOwnPropertyDescriptors returns all own property
descriptors of a given object.
value— The value associated with the property (data descriptors only).
writable— true if, and only if, the value associated with the property may be changed.
get— A function that serves as a getter for the property.
set— A function that serves as a setter for the property.
configurable— True if, and only if, the type of this property descriptor may be changed.
enumerable— True if, and only if, this property shows up during enumeration of the property.
Trailing Commas in Function Parameter List and Calls
There are two benefits:
- You don’t have to add and remove commas if the last item changes its position.
- It helps version control systems with tracking what actually changed.
The async function declaration defines an asynchronous function — a function that returns an
Asynchronous functions operate in a separate order to the rest of the code via the event loop, returning an implicit Promise as its result. But the syntax and structure of code using async functions look like standard synchronous functions.
Shared Memory and Atomics
Atomics is a global variable whose methods have three main use cases.
- Waiting to be notified.
- Atomic operations.
The following example illustrates the use cases.
In this post, we have reviewed the features that arose in ES2017 (a.k.a. ES8).
Although many of these features may not be essential for the development of your web application, they offer possibilities that could be achieved before only with tricks or a lot of verbosity.