JavaScript Basic
What are the new features in ES2023?
ES2023 (ECMAScript 14) Key Features
1. Array.prototype.toSorted()
Returns a new sorted array without modifying the original (non-mutating).
const arr = [3, 1, 2];
const sorted = arr.toSorted(); // [1, 2, 3]
console.log(arr); // [3, 1, 2] (unchanged)
2. Array.prototype.toReversed()
Returns a new reversed array without modifying the original.
const arr = [1, 2, 3];
const reversed = arr.toReversed(); // [3, 2, 1]
console.log(arr); // [1, 2, 3] (unchanged)
3. Array.prototype.toSpliced()
Returns a new array with splice applied without modifying the original.
const arr = [1, 2, 3, 4];
const result = arr.toSpliced(1, 2, 'a', 'b'); // [1, 'a', 'b', 4]
console.log(arr); // [1, 2, 3, 4] (unchanged)
4. Array.prototype.with()
Returns a new array with one element replaced without modifying the original.
const arr = [1, 2, 3];
const result = arr.with(1, 99); // [1, 99, 3]
console.log(arr); // [1, 2, 3] (unchanged)
5. Array.prototype.findLast() and findLastIndex()
Search from the end of the array.
const arr = [1, 2, 3, 4, 5];
arr.findLast(n => n % 2 === 0); // 4
arr.findLastIndex(n => n % 2 === 0); // 3
6. Hashbang Grammar (#!)
Allows #! at the start of scripts for Unix shebang support.
#!/usr/bin/env node
console.log('Hello!');
7. WeakMap Keys with Symbols
const key = Symbol('key');
const map = new WeakMap();
map.set(key, 'value');
Summary
ES2023's highlight is a set of non-mutating array methods that make functional programming more convenient and prevent accidental mutation of original data.
✦ AI Mock Interview
Type your answer and get instant AI feedback
Sign in to use AI scoring
