Modern JavaScript Features in ES202X: A Developer’s Overview

Table of Contents
Big thanks to our contributors those make our blogs possible.

Our growing community of contributors bring their unique insights from around the world to power our blog. 

Introduction

JavaScript is one of the most actively evolving programming languages, thanks to the annual ECMAScript (ES) updates introduced by TC39. Each ES release adds new syntax, features, and patterns that improve developer productivity, code readability, and runtime performance.

In this post, we provide a practical overview of modern JavaScript features introduced in recent ECMAScript versions, including ES2021, ES2022, and ES2023 (and a look ahead at what’s coming in ES2024). Whether you’re writing modern frontend applications or building backend services with Node.js, these features can help you write cleaner, faster, and more maintainable code.

Why Stay Updated with JavaScript Features?

  • Improved developer experience: Cleaner syntax and better tooling.
  • Enhanced performance: Native features often run faster than polyfilled alternatives.
  • More expressive code: Write logic that’s closer to your intent.
  • Better browser support: Evergreen browsers adopt new features quickly.

ES2021 (ECMAScript 2021) Highlights

1. String.prototype.replaceAll()

Replaces all instances of a substring without needing a regular expression.

javascriptCopyEditconst text = 'hello world world';
console.log(text.replaceAll('world', 'JavaScript')); // "hello JavaScript JavaScript"

2. Logical Assignment Operators

Combine logical and assignment operations:

javascriptCopyEdita ||= b;  // a = a || b
a &&= b;  // a = a && b
a ??= b;  // a = a ?? b

3. Numeric Separators

Improves number readability:

javascriptCopyEditconst budget = 1_000_000; // Easier to read

4. Promise.any()

Resolves as soon as any promise resolves (ignores rejected promises unless all fail):

javascriptCopyEditPromise.any([p1, p2, p3])
  .then(value => console.log(value))
  .catch(error => console.error(error));

5. WeakRefs and Finalizers (Advanced)

Used for manual memory management—rarely used in frontend development but powerful for libraries and frameworks.

ES2022 (ECMAScript 2022) Highlights

1. Class Fields and Static Initialization Blocks

Define private and public class fields directly:

javascriptCopyEditclass User {
  #password;
  constructor(password) {
    this.#password = password;
  }
}

Static blocks:

javascriptCopyEditclass Config {
  static settings;
  static {
    Config.settings = loadConfig();
  }
}

2. Top-Level await

Use await outside of async functions—ideal for modules:

javascriptCopyEdit// works inside an ES module (.mjs or type="module")
const data = await fetch('/api/data').then(res => res.json());

3. Error Cause

Add context to thrown errors:

javascriptCopyEdittry {
  throw new Error('Database failure', { cause: 'Timeout' });
} catch (e) {
  console.log(e.cause); // "Timeout"
}

ES2023 (ECMAScript 2023) Highlights

1. Array.prototype.toSorted(), toReversed(), toSpliced()

Non-mutating versions of common array operations:

javascriptCopyEditconst nums = [3, 1, 2];
const sorted = nums.toSorted(); // [1, 2, 3]
const reversed = nums.toReversed(); // [2, 1, 3]
const spliced = nums.toSpliced(1, 1); // Removes 1 item at index 1

2. Symbol.prototype.description Writable

Symbol descriptions can now be modified after creation.

javascriptCopyEditlet sym = Symbol('initial');
sym.description = 'updated'; // Previously read-only

3. Array.prototype.findLast() and findLastIndex()

Search from the end of the array:

javascriptCopyEditconst nums = [1, 2, 3, 4, 5];
const lastEven = nums.findLast(n => n % 2 === 0); // 4

What’s Coming in ES2024 and Beyond (Preview)

While not yet finalized, these proposals are in Stage 3 or Stage 4 (close to adoption):

1. Set Methods

More intuitive operations on Set objects:

javascriptCopyEditset1.union(set2);
set1.intersection(set2);
set1.difference(set2);

2. Pattern Matching (Proposed)

A potential switch-like construct for deep matching:

javascriptCopyEditmatch (data) {
  { type: 'user', id } => handleUser(id),
  { type: 'admin', permissions } => handleAdmin(permissions),
}

3. Pipeline Operator (|>) (Experimental)

Improves function chaining readability:

javascriptCopyEditconst result = value
  |> stepOne
  |> stepTwo
  |> stepThree;

Note: This syntax is still experimental and subject to change.

Best Practices When Adopting New Features

  • Check browser compatibility using Can I Use
  • Use transpilers like Babel if targeting older browsers
  • Keep your tooling up to date (Node.js, Webpack, TypeScript, etc.)
  • Adopt incrementally: don’t refactor everything at once

Conclusion

Modern JavaScript features provide developers with powerful tools to write cleaner, more efficient, and more expressive code. By staying current with the latest ECMAScript updates—from ES2021 to ES2023 and beyond—you can build better applications and take full advantage of what the language offers today.

Whether you’re building frontend SPAs or full-stack applications with Node.js, understanding and applying these features will keep your codebase modern, performant, and maintainable.

Let's connect on TikTok

Join our newsletter to stay updated

Sydney Based Software Solutions Professional who is crafting exceptional systems and applications to solve a diverse range of problems for the past 10 years.

Share the Post

Related Posts