ES11 (ECMAScript 2020) introduced BigInt for large integers, nullish coalescing, optional chaining, and dynamic imports.
June 2020
ES11 (ECMAScript 2020) introduced BigInt for large integers, nullish coalescing, optional chaining, and dynamic imports.
Try out JavaScript code examples and experiment with features in the official TypeScript playground.
Open JavaScript PlaygroundBuilt-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); // TypeErrorReturns 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)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 existReturns 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 }
// ]
});