More Modern Features

Quick Tour

Example

// exponent, numeric separators, BigInt
console.log(2 ** 8, 1_000_000, 2n ** 64n);
// Array helpers (ES2022/2023)
console.log([10, 20, 30].at(-1), [3, 1, 2].toSorted(), { ...Object.groupBy([1, 2, 3, 4], n => n % 2 ? "odd" : "even") });
// string helpers
console.log("ha ".repeat(2).trimEnd(), "a-b-c".replaceAll("-", "+"));
// logical assignment
let config = {};
config.retries ||= 3;
console.log(config);

Output

256 1000000 18446744073709551616n
30 [ 1, 2, 3 ] { odd: [ 1, 3 ], even: [ 2, 4 ] }
ha ha a+b+c
{ retries: 3 }

Feature Timeline

VersionHighlights
ES2015 (ES6)let/const, arrow functions, classes, modules, promises, destructuring, template literals, Map/Set
ES2017async/await, Object.entries/values
ES2020optional chaining, nullish coalescing, BigInt, Promise.allSettled
ES2022top-level await, class fields and private #fields, .at()
ES2023+toSorted/toReversed, findLast, Object.groupBy (2024)