Featured image of post Exciting Features in ECMAScript 2025 (ES16) Featured image of post Exciting Features in ECMAScript 2025 (ES16)

Exciting Features in ECMAScript 2025 (ES16)

Take a preview look at the upcoming standard API proposals in ECMAScript 2025, detailing Promise.try, Iterator Helpers, and native Set operations.

Introduction

Each year, the TC39 committee updates the ECMAScript specifications, introducing new language features and APIs to the JavaScript ecosystem.

For the upcoming ECMAScript 2025 (ES16) standard, several proposals have reached Stage 3 or Stage 4, indicating they are in the final stages of browser implementation and adoption.

This article highlights some of the new features coming in ES2025, detailing how they simplify coding patterns.


1. Promise.try: Unifying Synchronous and Asynchronous Error Handling

A common challenge in JavaScript development is handling both synchronous exceptions and asynchronous Promise rejections in a clean, unified way.

To address this, the TC39 committee introduced Promise.try().

The Challenge

When calling a function runTask that might throw either a synchronous exception or return a rejected Promise, handling both error types cleanly can be difficult.

// Handling both error types requires redundant boilerplate
function handleTask(runTask) {
  try {
    const result = runTask();
    if (result instanceof Promise) {
      result.catch(err => console.error("Async error:", err));
    }
  } catch (err) {
    console.error("Sync error:", err);
  }
}

Clean Implementation with Promise.try

Promise.try() executes the passed callback. If the callback throws a synchronous exception, Promise.try() catches the exception and returns a rejected Promise. This allows you to chain a single .catch() handler to catch both synchronous and asynchronous errors.

function handleTask(runTask) {
  Promise.try(runTask)
    .then(result => console.log("Result:", result))
    .catch(err => console.error("Unified error handler:", err));
}

2. Iterator Helpers: Map and Filter on Iterators

Although arrays natively support .map() and .filter(), JavaScript Map and Set iterators (like .keys() or .values()) have historically lacked these methods.

ES2025 addresses this by introducing Iterator Helpers, which bring utility methods to all iterator objects.

Code Example

const mySet = new Set([1, 2, 3, 4, 5]);

// Chain filter and map directly on the Set iterator
const processed = mySet.values()
  .filter(x => x % 2 !== 0) // Keep only odd numbers
  .map(x => x * 10);        // Multiply by 10

for (const value of processed) {
  console.log(value); // Outputs: 10, 30, 50
}
  • Lazy Evaluation: Iterator Helpers use lazy evaluation, meaning items are processed only when requested. This allows you to work with large datasets or infinite streams without allocating memory for intermediate arrays.

3. Standard Set Operations

The native JavaScript Set class receives updates to support standard mathematical set operations.

Instead of writing custom loops to calculate unions and intersections, developers can now run these operations using native helper methods.

New Set Methods

  • union(): Returns a set containing all elements from both sets.
  • intersection(): Returns a set containing only elements present in both sets.
  • difference(): Returns a set containing elements present in the first set but not the second.
  • symmetricDifference(): Returns a set containing elements present in either set, but not both.

Code Example

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

// Calculate the intersection (common elements)
const common = setA.intersection(setB);
console.log(common); // Set { 3 }

// Calculate the union (all unique elements)
const combined = setA.union(setB);
console.log(combined); // Set { 1, 2, 3, 4, 5 }

Conclusion and Browser Support

The new APIs in ECMAScript 2025 replace custom helper libraries (like Lodash) with native, optimized implementations built directly into the browser’s JavaScript engine.

Most of these proposals are already implemented in experimental or beta versions of Chrome, Edge, and Safari, and can be used in development by updating your Babel or TypeScript transpilation targets.

Prepare for these upcoming standard additions to write cleaner, more efficient JavaScript.