JS 2018 - ECMAScript 2018
Last Updated :
24 Aug, 2023
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:
- Asynchronous Iteration
- Promise Finally
- Object Rest Properties
- New RegExp Features
- SharedArrayBuffer
We will explore all the above methods along with their basic implementation with the help of examples.
Method 1: Asynchronous Iteration
Asynchronous 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
const myArray = [1, 2, 3, 4, 5];
// A function that returns a promise
// that resolves after a random delay
async function doSomethingAsync(item) {
return new Promise(resolve => {
setTimeout(() => {
console.log(item);
resolve();
}, Math.random() * 1000);
});
}
async function main() {
// Iterate over the array using a for-of loop
for (const item of myArray) {
// Wait for the promise returned
//by doSomethingAsync to resolve
await doSomethingAsync(item);
}
}
// Call main to start the program.
main();
Output:

Promise.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
// Define the Promise
let task = new Promise((resolve, reject) => {
setTimeout(() => {
// Reject the Promise
reject("Promise has been rejected!");
}, 2000);
});
task
.then(
(data) => {
console.log(data);
},
// Handle any error
(error) => {
console.log("Error:", error);
}
)
// Specify the code to be executed
// after the Promise is settled
.finally(() => {
console.log(
"This is finally() block that is " +
"executed after Promise is settled"
);
});
Output:
Error: Promise has been rejected!
This is finally() block that is executed after Promise is settled
Method 3: Object Rest Properties
Object 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
const person = {
firstName: 'Rohan',
lastName: 'Nanda',
age: 23,
city: 'Noida'
};
let { firstName, lastName, ...rest } = person;
console.log(firstName);
console.log(lastName);
console.log(rest);
OutputRohan
Nanda
{ age: 23, city: 'Noida' }
Method 4: New RegExp Features
- Unicode Property Escapes (\p{...}) : matches characters based on Unicode properties or categories in regular expressions.
- Lookbehind Assertions (?<= ) and (?<! ): matches if preceded by pattern, (?<!...) matches if not preceded, enhancing regex flexibility.
- Named Capture Groups: Named Capture Groups assign names to regex captures for organized data extraction and manipulation.
- s (dotAll) Flag: to match newline characters, improving regex pattern matching across lines.
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
const text = 'GeeksforGeeks';
// Unicode Property Escapes
const letterRegex = /\p{Letter}+/gu;
console.log(text.match(letterRegex));
// Lookbehind Assertions
const positiveLookbehind = /(?<=Geeks)for/;
console.log(text.match(positiveLookbehind));
const negativeLookbehind = /(?<!Geeks)for/;
console.log(text.match(negativeLookbehind));
// s (dotAll) Flag
const dotAllRegex = /G.+s/s;
console.log(text.match(dotAllRegex));
// Named Capture Groups
const regex = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
const match = regex.exec('2023-08-14');
console.log(match.groups.year);
console.log(match.groups.month);
console.log(match.groups.day);
Output[ 'GeeksforGeeks' ]
[ 'for', index: 5, input: 'GeeksforGeeks', groups: undefined ]
null
[
'GeeksforGeeks',
index: 0,
input: 'GeeksforGeeks',
groups: undefined
]
2023
08
14
Method 5: SharedArrayBuffer
SharedArrayBuffer 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
// Create a SharedArrayBuffer and an Int32Array view
const sharedBuffer = new SharedArrayBuffer(4);
const sharedArray = new Int32Array(sharedBuffer);
// Modify the shared value in the main thread
sharedArray[0] = 42;
// Log the shared value
console.log(sharedArray[0]);
Supported browser:
- Chrome 1
- Edge 12
- Firefox 1
- Safari 1
- Opera 3
Similar Reads
JavaScript ES5 (JS 2009)
JavaScript 2009 (ES5) refers to the fifth edition of the ECMAScript language specification, standardized in 2009. It introduced several features, like strict mode, new methods, JSON support, and improved syntax for better programming practices and compatibility across browsers. ECMAScript 5 (ES5) in
7 min read
ES2015: Latest Version of JavaScript
ES2015 is the latest version of JavaScript programming language. It is the first major upgrade to JavaScript since 1997. It was approved in June 2015 by ECMA international, an association responsible for approving ECMA standards which programming languages like JavaScript, CoffeeScript and TypeScrip
4 min read
JS 2015 or ECMAScript 6 (ES6)
JS 2015 (ES6) also known as ECMAScript 6 (ES6), ECMAScript 6 (ES6) is a significant update to JavaScript, introducing arrow functions, classes, template literals, let and const for variable declaration, enhanced object literals, destructuring, and more modern features for better code organization an
10 min read
JS 2016 or ECMAScript 2016
JavaScript 2016 (ES2016) is a modified version of ES2015 in which they introduced some new features like JavaScript Exponentiation (**) operator, JavaScript Exponentiation assignment (**=), and Array..includes() method for array element presence checking, enhancing calculations, and array operations
2 min read
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
3 min read
JS 2018 - ECMAScript 2018
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.
4 min read
JS 2019 - ECMAScript 2019
ECMAScript 2019, also known as ES10, introduced features like Array.flat(), Array.flatMap(), Object.fromEntries(), and Symbol. description, and some string methods, for enhancing JavaScript's capabilities and expressiveness. JavaScript 2019 (ES10) or ECMAScript 2019 new features are: Name Descriptio
5 min read
JS 2020 - ECMAScript 2020
JavaScript ECMAScript 2020 (ES11) introduced new features like optional chaining, nullish coalescing, dynamic import(), BigInt, and Promise.allSettled(), etc. enhancing language capabilities for modern web development needs. JavaScript 2020 (ES11) or ECMAScript 2020 new features are: BigInttype for
5 min read
ECMAScript 2021 (JS 2021/2022)
JavaScript in 2021/2022 continues to evolve, with ES2021/ES2022 bringing enhanced features like private class fields, promise improvements, and record data structures, boosting developer productivity and code quality. JavaScript New Features in ES2021Name Description Promise any(): Resolves if any P
4 min read
New Features in ECMAScript 2021 Update
ECMAScript is a part of JavaScript language which is mostly used in web technology, building websites, or web apps. ECMAScript is growing as one of the world's most widely used general-purpose programming languages. It is majorly used in embedding with web browsers and is also adopted for server and
4 min read