Skip to content

The Future of JavaScript: ECMAScript 2023 Highlights

06/06/20232 min read

Explore ECMAScript 2023: findLast, Hashbang, WeakMap symbols, and copy-by-change arrays, with runnable examples.

Open in
Hand-drawn illustration of the portling editing a photocopied array while the original stays pristine

ECMAScript 2023 landed at the end of June 2023. Four stage-4 proposals made the cut.

Array find from last proposal

This proposal adds the findLastIndex() prototype method which does the same thing as the findIndex() method but in reverse order.

findLastIndex() mirrors findIndex() in reverse. Run it here, or hit Edit and poke at it:

const arr = [1, 2, 3, 4, 5];
const index = arr.findLastIndex((element) => element > 2);
console.log(index); // Output: 4

Hashbang Grammar

Hashbang is a character sequence preceding an executable script. ECMAScript 2023 adds support for #! comments at the beginning of files to help make ECMAScript files directly executable.

Symbols as WeakMap keys

Objects were the only WeakMap keys. This proposal lets unique symbols in too, which closes the last gap for truly private keys.

Change array by copy

toSpliced() is splice() by copy. The original stays intact.

const arr = [1, 2, 3, 4, 5];
arr.splice(2, 2, 6, 7);
console.log(arr); // Output: [1, 2, 6, 7, 5] (original mutated)
const arr = [1, 2, 3, 4, 5];
const newArr = arr.toSpliced(2, 2, 6, 7);
console.log(newArr); // Output: [1, 2, 6, 7, 5] (original intact)

Did this resonate?