ECMAScript 2023 (ES14) — what to expect

nairihar
3 min readApr 16, 2023

--

There are four finished proposals this year for ECMAScript 2023 (ES14). All four are listed on GitHub as completed proposals, which are nearing official release. It is anticipated that they will be officially released in June 2023.

https://github.com/tc39/proposals/blob/main/finished-proposals.md

Let’s now take a closer look at each of these proposals.

Array find from last

This proposed feature would function similarly to Array.prototype.find and Array.prototype.findIndex, but with the key difference, it would iterate from the last element to the first.

const array = [{ value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }];

array.find(n => n.value % 2 === 1); // { value: 1 }
array.findIndex(n => n.value % 2 === 1); // 0

array.findLastIndex(n => n.value % 2 === 1); // 2
array.findLastIndex(n => n.value === 42); // -1

Hashbang Grammar

Essentially, if we create a JavaScript/Node.js CLI command like this, the system should automatically detect and remove the first line before executing Node.js. This is because the first line is not a valid JavaScript code and interpreters may return an error when encountering it.

#!/usr/bin/env node

console.log('Hey!');

So, this proposal suggests enhancing the syntax of JavaScript.Furthermore, the system will not require the extra step of removing the first line before executing Node.js.

Symbols as WeakMap keys

Simply put, WeakMaps will now have support for Symbols.

const weak = new WeakMap();

const key = Symbol('something');
const someObject = { /**/ };

weak.set(key, someObject);

Change Array by copy

This proposal suggests the addition of the following function properties to Array.prototype:

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

All of these methods maintain the original state of the target Array and return a copy of it with the applied changes.

So those are immutable methods.

const sequence = [1, 2, 3];
sequence.toReversed(); // => [3, 2, 1]
sequence; // => [1, 2, 3]

const outOfOrder = new Uint8Array([3, 1, 2]);
outOfOrder.toSorted(); // => Uint8Array [1, 2, 3]
outOfOrder; // => Uint8Array [3, 1, 2]

const correctionNeeded = [1, 1, 3];
correctionNeeded.with(1, 2); // => [1, 2, 3]
correctionNeeded; // => [1, 1, 3]

Summary

As it is still April and we have some time until June, there is a possibility of more features being included in the ECMAScript 2023 release.

I hope you have found this article informative and enjoyable. Please feel free to reach out to me with any questions or comments you may have. @nairihar

--

--

nairihar

Sharing valuable insights on the latest tools and trends in JavaScript. nairi.dev