Member-only story
ES9 / ECMAScript2018
4. A Deep Dive into the Latest JavaScript Features — ES9
The JavaScript has been evolved a lot and one of the widely used language in the world. We are discussing about some core feature of ES9 / ECMAScript 2018 / ECMA2018, the iteration of the ECMAScript standard. Let’s talk about exciting features that can streamline your workflow and enhance your code.
In this article, we’ll delve into some of the key features introduced in ES9:
1. Asynchronous Iteration
Asyn iterator is powerful syntax to call async task in sync manner.
function fetcher(task,time) {
return new Promise(function(res) {
setTimeout(function() {
res(`${task} Done`);
}, time);
})
}const tasks = [1,2,3,4].map(d => {
return fetcher(d, 1000* d);
});
(async () => {
for await (const value of tasks) {
console.log(value);
}
})();2. Promise.prototype.finally()
Promises now have a finally block, which will be executed after then or catch block.
If we have any task that needs to be done in both then and catch block, we can now simply do that in finally block.










