ES2023 Features

With 2023 finally behind us, we can take a look at all of the new features added to JavaScript. ES2023 adds many useful array methods, and other helpful features.

Array Methods

Array.findLast and Array.findLastIndex

To start off we have the two array method findLast and findLastIndex. They are similar to their find and findIndex counterparts. findLast simply iterates over a array from right to left and returns the first element that satisfies callback. findLastIndex is similar but simply returns the first index instead of the first element.

See the Pen ES2023 Features (Example 1) by Kyle Ross (@kylejamesross) on CodePen.

Immutable Array Methods

ES2023 adds several immutable array methods to JavaScript. These methods will return a new copy of an array without mutating the original array.

Array.toReversed

Returns a reversed copy of the array.

Array.toSorted

Returns a sorted copy of the array.

Array.toSpliced(start, deleteCount, ...itemsToAdd)

Returns a spliced copy of the array.

Array.with(index, itemToReplace)

Returns a copy of the array with the item at the index replaced.

See the Pen CodePen Home ES2023 Features (Example 1) by Kyle Ross (@kylejamesross) on CodePen.

Shebang Grammar

The Shebang is the combination of the # (pound key) and ! (exclamation mark). It is included in the first line of a script. It is used by the interpreter to determine what will run the given script. This support has now been officially added to JavaScript. This now makes it easier to evaluate JavaScript from scripts. The following is an example of how to run a script in NodeJS.

See the Pen ES2023 Features (Example 3) by Kyle Ross (@kylejamesross) on CodePen.