ES11 APIs & Features

ES11 (ECMAScript 2020) introduced BigInt for large integers, nullish coalescing, optional chaining, and dynamic imports.

Released: June 2020
Modern JavaScript
ECMAScript

Other JavaScript Versions

Release Information

Release Date:

June 2020

Version Type:
Modern

Quick Summary

ES11 (ECMAScript 2020) introduced BigInt for large integers, nullish coalescing, optional chaining, and dynamic imports.

Top Features

  • BigInt
  • Nullish Coalescing Operator (??)
  • Optional Chaining (?.)
  • Promise.allSettled
  • Dynamic import()
  • globalThis

Playground

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

Open JavaScript Playground

API Examples

BigInt

Built-in object that provides a way to represent whole numbers larger than 2^53 - 1.

const bigInt = 9007199254740991n;
const anotherBigInt = BigInt(9007199254740991);

console.log(bigInt + 1n); // 9007199254740992n
console.log(typeof bigInt); // "bigint"

// Cannot mix with regular numbers
// console.log(bigInt + 1); // TypeError

Nullish Coalescing Operator (??)

Returns the right-hand operand when the left-hand operand is null or undefined.

const value = null;
const defaultValue = "default";

console.log(value ?? defaultValue); // "default"
console.log(0 ?? defaultValue); // 0 (not null/undefined)
console.log("" ?? defaultValue); // "" (not null/undefined)
console.log(false ?? defaultValue); // false (not null/undefined)

Optional Chaining (?.)

Safely access nested object properties without throwing an error if a reference is nullish.

const user = {
  name: "John",
  address: {
    street: "123 Main St"
  }
};

console.log(user?.address?.street); // "123 Main St"
console.log(user?.address?.city); // undefined
console.log(user?.contact?.phone); // undefined

// With function calls
const result = user?.getName?.(); // undefined if getName doesn't exist

Promise.allSettled

Returns a promise that resolves after all of the given promises have either fulfilled or rejected.

const promises = [
  Promise.resolve(1),
  Promise.reject("error"),
  Promise.resolve(3)
];

Promise.allSettled(promises).then(results => {
  console.log(results);
  // [
  //   { status: "fulfilled", value: 1 },
  //   { status: "rejected", reason: "error" },
  //   { status: "fulfilled", value: 3 }
  // ]
});