DEV Community

Cover image for ECMAScript 2023: Fresh Goodies for JavaScript Developers
Navdeep Mishra
Navdeep Mishra

Posted on • Updated on

ECMAScript 2023: Fresh Goodies for JavaScript Developers

Greetings, fellow code warriors! ⚔️ The JavaScript landscape is constantly evolving, and with the arrival of ECMAScript 2023 (ES14) in June 2023, we've got a new batch of tools to craft even more powerful and elegant applications. Let's explore some of the coolest features and unleash their potential in your code!

1. Array Enhancements: Supercharge your data wrangling. All these new methods are called copying methods. They return a new array instead of modifying the actual array.

  • toReversed: Say goodbye to .reverse() loops! This method lets you flip your arrays with a single, readable line:
const numbers = [3, 1, 4, 2];
const reversedNumbers = numbers.toReversed(); // [2, 4, 1, 3]

Enter fullscreen mode Exit fullscreen mode
  • toSorted: Taming unruly data becomes a breeze. Sort your arrays in natural order. The toSorted() method of Array instances is the copying version of the sort() method. It returns a new array with the elements sorted in ascending order. You can also pass a compare function just like our good old sort method.
const fruits = ["apple", "banana", "mango", "kiwi"];
const sortedFruits = fruits.toSorted(); // ["apple", "banana", "kiwi", "mango"]
Enter fullscreen mode Exit fullscreen mode
  • toSpliced: Need precise surgical edits? toSpliced adds or removes elements at specific indexes:
const letters = ["a", "b", "c", "d", "e"];
const editedLetters = letters.toSpliced(2, 1, "x", "y"); // ["a", "b", "x", "y", "d", "e"]
Enter fullscreen mode Exit fullscreen mode

2. Symbols as WeakMap Keys: Unleash memory magic

WeakMaps hold references to objects without preventing garbage collection. Now, you can use symbols as keys, making your code even more memory-efficient!

const symbolKey = Symbol("MySecretId");
const weakMap = new WeakMap();
weakMap.set(symbolKey, document.body); // Reference held without keeping element alive

// ... later, symbolKey can still access the element

Enter fullscreen mode Exit fullscreen mode

3. Hashbang Standardization: Say hello to portable scripts

Shebang lines (#!) in your JavaScript files now have a standardized grammar, making them consistent and easier to run across different environments. No more confusion!

#!/usr/bin/env node
// Your amazing JavaScript code goes here
Enter fullscreen mode Exit fullscreen mode

4. Private Class Members (Stage 3): A peek into the future

While still under development, private class fields and methods promise to revolutionize code organization and data encapsulation. Get ready for cleaner, more secure classes!

5. Bonus Goodies:

Improved type inference for object literals simplifies and clarifies your code.
New BigInt asDate and BigInt asTime functions let you work with large time values effortlessly.
Stricter error handling in async functions makes debugging smoother.
Promise.prototype.finally provides a concise way to run code after any Promise outcome.

Remember: These are just a taste of the exciting possibilities in ES14. Explore the full spec and experiment with these features to take your JavaScript skills to the next level!

Share your favorite new ES14 feature in the comments below! Let's discuss how we can leverage these tools to build even better web experiences. 😎

And don't forget, the journey of learning never ends! Stay curious, stay code-hungry, and keep building amazing things!

Follow for more content 💓

Top comments (9)

oculus42 profile image
Samuel Rouse

Thanks for assembling this list! I'm very excited for several of these capabilities, especially the Promise .finally() to complete the equivalence of try/catch/finally.

Something important to note about the new array enhancements is that these new functions are non-mutating versions of existing functions, which MDN refers to as "copying" methods.

Your descriptions are valid for both the old and new versions, but the new versions will not modify the source array, which is the key factor.

Also, the description you have for .toSorted() is concise but inaccurate. .toSorted() accepts an optional sort comparison function, just like its mutating predecessor, .sort().

navdeepm20 profile image
Navdeep Mishra

Thankyou for your comment. 💓 Yes, these new methods are actually good because they are immutable versions. Also, Thankyou for your feedback ✨. I have updated the post.

trans profile image
7rans • Edited

As for #4, If they are like Java’s then it’s a nail in the coffin. Private members are a nightmare in Java. They prevent reusability of code — and that’s their whole point. If just one method is private that you find you need to override, you can’t. You will have to reimplement it and every other method that calls it.

navdeepm20 profile image
Navdeep Mishra

Yes, Let's see how they are going to implement it in JavaScript in the upcoming years.

paulafaria profile image
Paula Faria

Thanks for sharing!

I'm really looking forward to trying out the new features, especially the .finally() one.

matek075 profile image

I like people who cares about being up to date with knowleadge others people

navdeepm20 profile image
Navdeep Mishra

Thank you ✨

jackal__ profile image

groupBy method is also noice :D

navdeepm20 profile image
Navdeep Mishra

Yes, No doubt it's a great method. 🔥