ES9 APIs & Features

ES9 (ECMAScript 2018) introduced rest/spread properties for objects, asynchronous iteration, and improvements to regular expressions.

Released: June 2018
Modern JavaScript
ECMAScript

Other JavaScript Versions

Release Information

Release Date:

June 2018

Version Type:
Modern

Quick Summary

ES9 (ECMAScript 2018) introduced rest/spread properties for objects, asynchronous iteration, and improvements to regular expressions.

Top Features

  • Rest/Spread Properties for Objects
  • Asynchronous Iteration (for-await-of)
  • Promise.finally
  • RegExp improvements (lookbehind, named groups)
  • Template Literal Revision

Playground

Try out JavaScript code examples and experiment with features in the official TypeScript playground.

Open JavaScript Playground

API Examples

Rest/Spread Properties for Objects

Extract and spread object properties similar to arrays.

const obj = { a: 1, b: 2, c: 3, d: 4 };

// Rest properties
const { a, b, ...rest } = obj;
console.log(rest); // { c: 3, d: 4 }

// Spread properties
const newObj = { ...obj, e: 5 };
console.log(newObj); // { a: 1, b: 2, c: 3, d: 4, e: 5 }

Promise.finally

Execute code regardless of whether a promise is fulfilled or rejected.

fetch("/api/data")
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))
  .finally(() => {
    console.log("Request completed");
  });

Asynchronous Iteration

Iterate over async iterables using for-await-of loop.

async function* asyncGenerator() {
  yield Promise.resolve(1);
  yield Promise.resolve(2);
  yield Promise.resolve(3);
}

async function example() {
  for await (const num of asyncGenerator()) {
    console.log(num); // 1, 2, 3
  }
}