Software
January 2, 2024

Exploring the Latest Features of Javascript 2023 (es2023) in less than 5 minutes

ECMAScript 2023 adds Array methods, Hashbang Grammar, Symbols as WeakMap keys, and non-mutating Array operations.

Introduction

Since the introduction of ES2015 (ES6 - modern JavaScript), incorporating features and changes to the JavaScript language has become more manageable and streamlined. Instead of massive updates every few years, we now witness a more incremental update process, where smaller modifications are added annually to the ECMAScript specification. With the release of ECMAScript 2023 (ES2023), developers can anticipate a suite of powerful new features aimed at increasing productivity, simplifying code, and enhancing overall performance. In this article, we will explore some of the most notable additions to JavaScript 2023 and discuss how these innovations will benefit the JavaScript community.

TC39 - Technical Committee 39 - is the committee responsible for iterating on and evolving the ECMAScript language specification. It follows an open-source model, and there is full transparency on language proposals. There are five main proposal stages:

  • Stage 0: "Straw-person": Represents the initial idea of an addition or change to the specification.
  • Stage 1: "Proposal": This stage describes a discrete problem or general need and suggests the shape of the solution.
  • Stage 2: "Draft": Represents a drafted proposal, detailing the feature's shape and addressing initial feedback for refinement.
  • Stage 3: "Candidate": The proposal has been thoroughly reviewed, deemed complete
  • Stage 4: "Finished": Final approval for a proposed ECMAScript feature, indicating readiness for inclusion in the standard.

Let's examine the latest proposals expected in JavaScript 2023 (ECMAScript 2023):

1. Array find from last

This proposal adds two new methods to the `Array` Object: `.findLast()` and `.findLastIndex()`. The benefits of this proposal are mainly Semantical and may improve the constant factors in time complexity ((i.e., how long it takes for the program to execute the same operation).

2. Hashbang Grammar

Hashbang comments are only valid at the start of a file for interpretters in various CLI environments. This proposal would move stripping the hashbang to actual Javascript engine instead of the CLI JS hosts that allow for Shebangs / Hashbang.

3. Symbols as WeakMap keys

`WeakMaps` are similar to `Maps`, but they allow the keys to be garbage collected if they are not referenced from somewhere other than a `WeakMap`. This proposal adds the ability to use `symbols` as `WeakMap` keys.

4. Change Array by Copy

One of the most annoying things in Javascript is Array methods that mutate the original array instead of returning a new one, like `Array.proptype.sort`.

This proposal adds 4 new array methods that keep the target array untouched and returns a copy of it with the changes performed instead. The first three methods will also be added to `TypedArrays`:

  • Array.prototype.toSorted(compareFn) -> Array
  • Array.prototype.toReversed() -> Array
  • Array.prototype.with(index, value) -> Array
  • Array.prototype.toSpliced(start, deleteCount, ...items) -> Array

Conclusion

In conclusion, ECMAScript 2023 promises to deliver impactful new features, streamlining JavaScript development and enhancing code quality. As the TC39 committee continues to refine and expand the language, developers can expect to see ongoing improvements, fostering increased productivity and innovation within the JavaScript ecosystem. By embracing these advancements, the JavaScript community is well-equipped to tackle future challenges and create more robust, efficient applications.