What's New In Javascript 2023!

What's New In Javascript 2023!

·

4 min read

In this article, we are going to see what new features are going to be introduced in es2023 so which is slated to be released somewhere between April to June of 2023, the version is also known as es14 because this is the 14th version of the ECMAScript specification which guides what features get introduced to the JavaScript language.

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.

1 . New array method :

let's have a look at the very first thing that is getting introduced and that is the new array method, we will get to see these three methods toReverse, toSorted, and toSplice because as of now these three methods have their equivalence where they mutate the underlying array in some cases we do not want to mutate the original array so for those cases now we can use these things. 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 ]

In these methods, the underlying array is not touched, so you can use these new methods to get your data while still keeping the original array intact.

2 . Finding elements from the last :

So, we have this method array findLast() and findLastIndex() , and using these methods you can find the element from the starting position but if you want to do it from the last position you cannot do it as of now after es 14 this changes and there are two new methods called find last and find the last index so find the last will actually find the last element that matches your condition

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

3 . Symbols as WeakMap keys :

In JavaScript, Objects and Symbols are guaranteed to be unique and cannot be re-created, which makes them both great candidates for the 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

4 . Hashbang Grammar :

Hashbang, also known as a shebang is a sequence of characters at the beginning of an executable script that defines the interpreter for the program to be run on. When the Unix kernel’s program loader executes a JavaScript program, the host strips the hashbang to generate a valid source before passing it down to the engine. Hashbang Grammar proposal by Bradley Farias standardizes how it is done.

const weak = new WeakMap();
const key = Symbol("ref");
weak.set(key, "ECMAScript 2023");

console.log(weak.get(key));
// ECMAScript 2023

Note :
As always, there are other interesting proposals that will take longer to reach the language, like type annotations, AsyncContext, and internationalization work that — along with Temporal — will replace some commonly used but large libraries with well-designed, ergonomic APIs built into the language. There are also higher-level initiatives around standardizing JavaScript runtimes, as well as the long-term question of what ECMAScript can address next: we’ll be looking at all of those soon**.**