JavaScript async and await
JavaScript async/await is a modern syntax for handling asynchronous operations. The async keyword defines a function that returns a promise, and await pauses execution until the promise is resolved or rejected.
Example 1: In this example, we will see the basic use of async in Javascript.
Javascript
const getData = async () => { let data = "Hello Geeks" ; return data; } getData().then(data => console.log(data)); |
Hello Geeks
Example 2: This example shows the basic use of the await keyword in Javascript.
Javascript
const getData = async () => { let y = await "Hello Geeks" ; console.log(y); } console.log(1); getData(); console.log(2); |
1 2 Hello Geeks
JS 2017 – ECMAScript 2017
JavaScript (JS) 2017, or ECMAScript 2017, introduced some new features in JavaScript. It enhanced asynchronous programming with async functions, provided shared memory and atomics for improved concurrency, and introduced Object.values() and Object.entries() for streamlined object manipulation. These additions expanded JavaScript’s capabilities, making it more versatile and powerful for modern development.
JavaScript (JS) 2017 new features are:
- String padding
- Object entries() Method
- Object values() Method
- async and await
- Object.getOwnPropertyDescriptors
We will explore all the above methods along with their basic implementation with the help of examples.