- read

πŸ’‘ JavaScript ES14: The New Kid on the Block πŸ‘¦

Kedar Pethe 24

πŸ’‘ JavaScript ES14: The New Kid on the Block πŸ‘¦

Kedar Pethe
JavaScript in Plain English
2 min read3 days ago

--

Photo by Ben White on Unsplash

ES14 or ECMAScript 2023 is the latest version of JavaScript.
It was released in June 2023.

As Brendan Eich, the creator of JavaScript, once said:

β€œAlways bet on JavaScript.”

It has four new features:

Searching arrays from the end πŸ”

This feature lets us find an element or its index from the end of an array. For example:

let nums = [2, 4, 6, 8, 9, 10];
let lastOddNum = nums.findLast(n => n% 2 === 1); // 9
let lastOddNumIndex = nums.findLastIndex(x => x % 2 === 1); // 4

Introduction of Hashbang Grammar πŸ“š

Hashbang is a character sequence (#!) that tells the OS which interpreter to use for a script. For example:

#!/usr/bin/env node
console.log("Hello JS ES 14!");

The different interpreters allowed are NodeJS, PERL, PHP, Python and Ruby. In above script we are using β€œNodeJS” as interpreter name.
Hashbang was not supported by JavaScript until ES14.

Symbols can now be WeakMap keys πŸ”‘

Symbols are unique, unchangeable identifiers for object properties.
They let you attach data to objects without altering the object or causing memory leaks, making them ideal for adding metadata to objects outside your control.

For example:

let weakMap = new WeakMap();
let symbolRef = Symbol("sym");
weakMap.set(symbolRef, {value: 121212});
console.log(weakMap.get(symbolRef)); // {value: 121212}

Modifying arrays by copying πŸ”„

This feature introduces four new methods: with, toSorted, toReversed, and toSpliced that modify an array and return a new one, leaving the original array unchanged.

For example:

let originalScientists = ["Raman", "Bose", "Kalam", "Chandrasekhar"];
let modifiedScientists = originalScientists.with(0, "Sarabhai").toSorted().toSpliced(1, 2, "Bhabha", "Rao").toReversed();
console.log(modifiedScientists); // ["Sarabhai", "Rao", "Bhabha", "Bose"]
console.log(originalScientists); // ["Raman", "Bose", "Kalam", "Chandrasekhar"]

Conclusion

ES14 adds new JavaScript features. They’re not universally supported yet, but can be used with transpilers or polyfills.

It’s been a wild ride, right? But don’t worry, we’ve got some cooler stuff coming up. πŸ€–

Happy coding! Stay tuned! 😊

Bonus Tip: Check out my React 2023 Refresher YouTube videos here.

In Plain English

Thank you for being a part of our community! Before you go: