What's new in ECMAScript 2023
Last and most important thing is that we are cutting ES2023. We are freezing it, or rather we have frozen it, I should say. We are not expecting any more significant editorial changes. There will be at least a couple very small editorials tweaks that will land but nothing large.
Let me share the list of all the new features that reached stage 4 and are expected to be included in the upcoming ECMAScript version. Exactly what I did in 2022, 2021, 2020, 2019, 2018, 2017 and 2016.
Array find from last
Array find from the last proposal by Wenlu Wang adds
findLastIndex() methods on
TypedArray prototype. They do the same thing as
findIndex() but in reverse order. Both methods are handy and let us skip creating temporary duplicates, mutations and confusing index substractions.
const isEven = (number) => number % 2 === 0; const numbers = [1, 2, 3, 4]; // from first to the last lookup console.log(numbers.find(isEven)); // 2 console.log(numbers.findIndex(isEven)); // 1 // from last to the first lookup console.log(numbers.findLast(isEven)); // 4 console.log(numbers.findLastIndex(isEven)); // 3
#!/usr/bin/env node console.log('hi 👋');
Symbols as WeakMap keys
WeakMap keys. Previous versions or specifications allowed only Objects to be used that way, but luckily Symbols as WeakMap keys proposal by Daniel Ehrenberg, Richard Button, Robin Ricard, Leo Balter, Rick Waldron and Caridy Patiño adds non-registered Symbols to the list of allowed keys.
const weak = new WeakMap(); const key = Symbol("ref"); weak.set(key, "ECMAScript 2023"); console.log(weak.get(key)); // ECMAScript 2023
Change Array by Copy
splice() methods on
Array.prototype mutate the array in place. Change Array by Copy proposal by Ashley Claymore and Robin Ricard adds equivalents of those methods that return a new copy —
toSpliced(). This proposal also adds a
with() method that returns a new array with the element at the given index replaced with the given value to avoid mutations in place using bracket notation.
const original = [1, 2, 3, 4]; const reversed = original.toReversed(); console.log(original); // [ 1, 2, 3, 4 ] console.log(reversed); // [ 4, 3, 2, 1 ]
const original = [1, 3, 2, 4]; const sorted = original.toSorted(); console.log(original); // [ 1, 3, 2, 4 ] console.log(sorted); // [ 1, 2, 3, 4 ]
const original = [1, 4]; const spliced = original.toSpliced(1, 0, 2, 3); console.log(original); // [ 1, 4 ] console.log(spliced); // [ 1, 2, 3, 4 ]
const original = [1, 2, 2, 4]; const withThree = original.with(2, 3); console.log(original); // [ 1, 2, 2, 4 ] console.log(withThree); // [ 1, 2, 3, 4 ]