![]() |
JavaScript 2018 (ES9) or ECMAScript 2018 is a modified version of ES8, in which ES9 introduced new features like asynchronous iteration, rest/spread properties, and enhancements to regular expressions, further improving asynchronous programming, object manipulation, and string handling capabilities. JavaScript 2018 (ES9) or ECMAScript 2018 new features are:
We will explore all the above methods along with their basic implementation with the help of examples. Method 1: Asynchronous IterationAsynchronous iteration allows looping over asynchronous data streams using for-await-of, we can use await keyword in for/of loop. Syntax: for await (variable of asynchronousIterable) {
// Code to be executed for each iteration
};
Example: In this example, we use async/await to iterate through myArray, calling doSomethingAsync() for each item. It waits for asynchronous tasks to complete before moving to the next iteration Javascript
Output: Method 2: Promise FinallyPromise.finally() executes a callback when a promise settles, either resolved or rejected, allowing cleanup operations regardless of the promise outcome. Syntax: task.finally(function() {
// Task to be performed when
// the promise is settled
});
Example: In this example we are using the above-explained approach. Javascript
Output: Error: Promise has been rejected!
This is finally() block that is executed after Promise is settled
Method 3: Object Rest PropertiesObject Rest Properties allow creating new objects with selected properties, simplifying object destructuring and recombination in JavaScript. Syntax: { var1, var2, ...rest } = person;
Example: In this example we are restructuring our object. Javascript
Output
Rohan Nanda { age: 23, city: 'Noida' } Method 4: New RegExp Features
Syntax: const regex = /\p{Property}/gu; // Unicode Property Escapes
const regex = /(?<=prefix)pattern/; //Lookbehind Assertions
const regex = /(?<groupName>pattern)/; //Named Capture Groups
const regex = /pattern/s; //s (dotAll) Flag
Example: In this example we are using the above-explained methods. Javascript
Output
[ 'GeeksforGeeks' ] [ 'for', index: 5, input: 'GeeksforGeeks', groups: undefined ] null [ 'GeeksforGeeks', index: 0, input: 'GeeksforGeeks', groups: undefined ] 2023 08 14 Method 5: SharedArrayBufferSharedArrayBuffer is a JavaScript feature that enables multiple threads to access and manipulate shared memory, aiding concurrent operations, but it requires synchronization to prevent race conditions. Syntax: const sharedBuffer = new SharedArrayBuffer(byteLength);
Example: In this example, a SharedArrayBuffer is created with a size of 4 bytes, and an Int32Array view is established over it. The value 42 is assigned to the shared array. Javascript
Output
42 Supported browser:
|
Reffered: https://www.geeksforgeeks.org
JavaScript |
Related |
---|
![]() |
![]() |
![]() |
![]() |
|
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |