JavaScript ES2024 Features You Should Be Using Now

Emma GeorgeEmma George
05 Jun, 2025
JavaScript ES2024 Features You Should Be Using Now

TABLE OF CONTENTS

1 . Introduction to ECMAScript

2 . Array Grouping with groupBy() and groupByToMap()

3 . Set Operations: union, intersection, difference, symmetricDifference

4 . Promise.withResolvers()

5 . Promise.withTimeout()

6 . Function.prototype.toString with Source Decorators

7 . Symbol.dispose and Symbol.asyncDispose

8 . import Attributes for Web Standard Alignment

10 . Conclusion and Future Outlook

Conclusion

JavaScript is one of the fastest-evolving languages in the programming world. Every year, the ECMAScript (ES) specification receives proposals that eventually become part of the core language, improving expressiveness, safety, and developer experience. ES2024 is no different. With this year’s update, developers get a set of new tools designed to write cleaner, more efficient code.

In this deep-dive guide, we’ll explore the latest JavaScript ES2024 features, how to use them, and why they matter.

1 . Introduction to ECMAScript

ECMAScript (ES) is the standard specification that JavaScript implementations (like V8, SpiderMonkey) follow. Each year, new features go through a rigorous proposal process from Stage 0 (strawman) to Stage 4 (finished). ES2024 (also known as ECMAScript 2024) introduces quality-of-life improvements that developers have long been waiting for.

While these features are new, many are already polyfilled or available in modern browsers and Node.js versions via flags or transpilers like Babel or TypeScript.

2 . Array Grouping with groupBy() and groupByToMap()

These two new methods allow you to group array items based on criteria you define—making data transformation cleaner than ever before.

✅ Syntax:

  • Array.prototype.groupBy(callback)
  • Array.prototype.groupByToMap(callback)

🧪 Example:

const inventory = [
  { type: 'fruit', name: 'apple' },
  { type: 'vegetable', name: 'carrot' },
  { type: 'fruit', name: 'banana' },
];

const grouped = inventory.groupBy(item => item.type);
/*
{
  fruit: [{ type: 'fruit', name: 'apple' }, { type: 'fruit', name: 'banana' }],
  vegetable: [{ type: 'vegetable', name: 'carrot' }]
}
*/

const groupedMap = inventory.groupByToMap(item => item.type);
/*
Map(2) {
  'fruit' => [...],
  'vegetable' => [...]
}
*/

🧠 Use Case: Perfect for dashboard analytics, reports, and data visualization where data categorization is required.

3 . Set Operations: union, intersection, difference, symmetricDifference

JavaScript’s Set object gets new instance methods to handle mathematical set operations more naturally.

✅ Syntax:

  • Set.prototype.union(otherSet)
  • Set.prototype.intersection(otherSet)
  • Set.prototype.difference(otherSet)
  • Set.prototype.symmetricDifference(otherSet)

🧪 Example:

const setA = new Set([1, 2, 3]);
const setB = new Set([2, 3, 4]);

setA.union(setB);              // Set {1, 2, 3, 4}
setA.intersection(setB);       // Set {2, 3}
setA.difference(setB);         // Set {1}
setA.symmetricDifference(setB); // Set {1, 4}

🧠 Use Case: Perfect for filtering user permissions, comparing datasets, or managing tags/tokens.

4 . Promise.withResolvers()

This static method returns an object with a promise and its corresponding resolve and reject functions, simplifying manual control over promises.

✅ Syntax:

const { promise, resolve, reject } = Promise.withResolvers();

🧪 Example:

const { promise, resolve } = Promise.withResolvers();

setTimeout(() => resolve('Done!'), 1000);

promise.then(result => console.log(result)); // "Done!" after 1 second

🧠 Use Case: Helps in scenarios like manual timeouts, external event triggers, or implementing custom queues.

5 . Promise.withTimeout()

Provides built-in support to auto-reject a promise after a timeout period.

✅ Syntax:

Promise.withTimeout(promise, timeoutMs, timeoutReason?)

🧪 Example:

const delayed = new Promise(resolve => setTimeout(() => resolve("Success"), 2000));

try {
  const result = await Promise.withTimeout(delayed, 1000, "Too slow");
} catch (err) {
  console.log(err); // "Too slow"
}

🧠 Use Case: Excellent for API requests, database queries, or async tasks that could hang.

6 . Function.prototype.toString with Source Decorators

This enhancement makes function source more inspectable by standardizing the output of toString(), including decorators and comments.

🧪 Example:

/**
 * Adds two numbers
 */
function add(a, b) {
  return a + b;
}

console.log(add.toString());

Output (formatted):

"/**
 * Adds two numbers
 */
function add(a, b) {
  return a + b;
}"

🧠 Use Case: Improves code documentation tools, debugging, and meta-programming utilities.

7 . Symbol.dispose and Symbol.asyncDispose

This introduces cleanup logic into objects, especially useful in resource management patterns.

✅ Example:

class FileHandle {
  [Symbol.dispose]() {
    console.log("File closed");
  }
}

With using declaration (hypothetical future syntax):

using fh = new FileHandle();

🧠 Use Case: Similar to Python’s with statement or C# using blocks—great for file systems, sockets, and database handles.

Note: Requires additional syntax support (stage 3 proposal at time of writing).

8 . import Attributes for Web Standard Alignment

ES2024 improves dynamic import attributes for things like JSON modules or CSS modules.

🧪 Example:

const jsonData = await import('./data.json', {
  with: { type: 'json' }
});

🧠 Use Case: Enhances clarity and loader support for web resources and asset management systems.

9 . ShadowRealm Enhancements

ShadowRealms are isolated JS execution environments introduced in ES2022. ES2024 continues to polish them.

Use Case:

  • Secure sandboxing
  • Safe code evaluation
  • Plugin architecture

🧪 Example:

const realm = new ShadowRealm();
const result = realm.evaluate(`1 + 1`);
console.log(result); // 2

🧠 Advanced Use Case: Secure remote code execution in SaaS platforms and IDEs.

10 . Conclusion and Future Outlook

ES2024 cements JavaScript’s position as a modern, expressive, and powerful programming language. From better control with promises to cleaner data transformation using groupBy() and smarter resource management via Symbol.dispose, these updates allow developers to write more readable, performant, and safer code.

Here’s a recap of what you can start using now:

  • Array.groupBy & groupByToMap – for structured data

  • Set operations – for clean mathematical logic

  • Promise.withResolvers & withTimeout – for fine-grained async control

  • import attributes – for robust resource handling

  • Function.toString improvements – for better dev tooling

  • Symbol.dispose – for secure and predictable cleanup

JavaScript is evolving, don’t get left behind. These new features are not just sugar; they’re the foundation of cleaner codebases and smarter systems.

🧠 Pro Tip: Keep your environments up to date and use polyfills or transpilers for backward compatibility.

Conclusion

JavaScript ES2024 introduces a powerful set of features that modern developers should begin integrating into their workflows. From simplified data transformations using groupBy and groupByToMap to intuitive set operations like union and intersection, the language now encourages more declarative and maintainable patterns.

Asynchronous programming is also evolving, Promise.withResolvers() and Promise.withTimeout() provide developers with fine-grained control over async flow, making complex UI and network handling simpler and more predictable. Add to that the evolution of built-in capabilities like import attributes and function metadata, and we have a JavaScript that's becoming more robust, introspective, and modular than ever before.

Although some features, like Symbol.dispose, are still gaining broader support, staying ahead of the curve means understanding and preparing for their adoption today. With the right tooling (like Babel, TypeScript, and modern Node.js versions), you can start leveraging these improvements even before they're fully mainstream.

In short: ✅ Code becomes more expressive ✅ Async logic becomes easier to manage ✅ Data handling becomes more elegant ✅ Resource cleanup becomes safer and clearer

Whether you're building enterprise software, working on frontend interfaces, or creating developer tools, ES2024 offers something meaningful for you. By embracing these changes now, you're not just writing better JavaScript, you're writing future-proof JavaScript.

Happy coding! 🚀

Emma George

Emma George

Software Engineer

Senior Software Engineer