ES2018: Async Iteration and More
Learn about key ES2018 JavaScript updates including async iteration using for-await-of loops, rest and spread syntax for objects, the Promise.finally method, and improved regular expression features such as dotAll flag, named capture groups, lookbehind assertions, and Unicode property escapes. This lesson helps you understand how these modern features enhance asynchronous operations, object handling, and pattern matching in JavaScript.
Rest / Spread for Objects
ES6 (ES2015) allowed us to do this?
Now we can use the rest/spread syntax for objects too, let’s look at how:
With the spread operator we can easily create a clone of our Object so that when we modify the original Object, the clone does not get modified.
Asynchronous iteration
With asynchronous iteration we can iterate asynchronously over our data.
An async iterator is much like an iterator, except that its
next()method returns a promise for a{ value, done }pair.
To do so, we will use a for-await-of loop which works by converting our iterables to a promise, unless they already are one.
During execution, an async iterator is created from the data source using the
[Symbol.asyncIterator]()method. Each time we access the next value in the sequence, we implicitly await the promise returned from the iterator method.