JavaScript: What’s new in ECMAScript 2018 (ES2018)?

Bramus!
Bramus!
Jan 31, 2018 · 4 min read

At the latest TC39 meeting the new features that will make it into the “ECMAScript® 2018 Language Specification” (ES2018) have been selected. All proposals that have reached stage-4 since the consolidation of ES2017 got selected. This post gives one a quick look at the features that made it into ES2018.


Object Rest/Spread Properties

When destructuring an object, Object Rest Properties allow you to collect the remaining properties of an object onto a new object. Think of it as a magic magnet attracting all leftovers.

I use this one myself a lot, especially in a React (Native) context where I pluck certain values from this.props for internal use, and then forward on all other props to the returned child component by spreading them again.

Additionally, if you turn your thinking-logic around a bit, Object Rest Properties provide you with a good way to remove a property from an object in an immutable way.


Asynchronous Iteration

With Asynchronous Iteration we get asynchronous iterators and asynchronous iterables. Asynchronous iterators just like regular iterators, except their next()method returns a promise for a { value, done } pair. To consume asynchronous iterables, we can now use the await keyword with for … ofloops.


Promise.prototype.finally()

Promise.prototype.finally() finalizes the whole promises implementation, allowing you to register a callback to be invoked when a promise is settled (either fulfilled, or rejected).

A typical use case is to hide a spinner after a fetch() request: instead of duplicating the logic inside the last .then() and .catch(), one can now place it inside .finally()


RegExp related features

In total 4 RegExp related proposals made it into ES2018:

I especially digg the “RegExp named capture groups” feature, as it improves readability:

More info on these features can be found at Mathias Bynens — one of the driving forces behind these proposals — his blog: ECMAScript regular expressions are getting better!


Other new Features

To top it off a tweak to template literals landed: when using tagged template literals the restriction on escape sequences are removed, thus allowing things like \xerxes. Before this tweak an error would be thrown because \x is the start of a hex escape with erxes not being a valid hex value.


What now?

Do note that not all these features are readily available in all browsers. Meaning that they’re Stage-4 means that they are finished, and that browser vendors should implement them .

As for the future, I’m already looking forward at what’s next to come for JavaScript. Things like the Optional Chaining Operator already get me very excited 😊

Frontend Weekly

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co

Bramus!

Written by

Bramus!

Freelance Creative Coder (current focus: JS/React/React Native). Geek. Scout. Diver (PADI Divemaster). Dadops of #finn and #tila. Blogs at bram.us

Frontend Weekly

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co