What are ES2023 - ES14 features?
1. Symbol.prototype.description is now writable
The description
property of a Symbol
object is now writable, meaning you can change it after the Symbol
is created.
2. Array findLast
and findLastIndex
methods
These methods allow you to search arrays from the end, making it easier to locate items starting from the last element.
const arr = [1, 2, 3, 4, 5];
const lastEven = arr.findLast(num => num % 2 === 0);
console.log(lastEven); // 4
const lastEvenIndex = arr.findLastIndex(num => num % 2 === 0);
console.log(lastEvenIndex); // 3
3. Hashbang Grammar
JavaScript now supports the use of #!
(hashbang) at the start of a script, enabling compatibility with Unix-like environments for direct script execution.
#!/usr/bin/env node
console.log("Hello, world!");
4. Change Array by Copy Methods
New methods such as toSpliced
, with
, toReversed
, and toSorted
allow for creating modified copies of arrays without mutating the original.
const arr = [1, 2, 3];
const newArr = arr.toReversed();
console.log(newArr); // [3, 2, 1]
console.log(arr); // [1, 2, 3] (original array is unchanged)
const spliced = arr.toSpliced(1, 1, 9);
console.log(spliced); // [1, 9, 3]
5. Auto-accessor properties
A new syntax for declaring accessors (getters and setters) in classes, simplifying property definitions.
class Example {
accessor value = 42;
}
const obj = new Example();
console.log(obj.value); // 42
obj.value = 100;
console.log(obj.value); // 100
6. RegExp v
flag for Unicode sets
The v
flag allows for more sophisticated matching of Unicode characters using Unicode property sets.
const regex = /\p{Emoji}/v;
console.log(regex.test("😊")); // true