Free JavaScript reference · Python timeline
JavaScript ES2025: Lazy iterator pipelines and new collection helpers
Iterator helpers, Set operations, RegExp.escape, and Promise.try add useful building blocks without changing browser support overnight.
Edition 16 · Published · Editorial review October 26, 2026
Standardized in ES2025 · Built-in method
Iterator helpers form lazy pipelines
Synchronous iterator helpers such as map, filter, and take let you build pipelines without first creating every intermediate array. Work is performed as the result is consumed. toArray explicitly materializes the remaining results.
Iterators are usually one-shot. Consuming or closing a pipeline can exhaust its source, so keeping a reference does not make it replayable. These synchronous helpers are also not promise-aware asynchronous mapping tools.
The example maps and takes only two values. A second toArray call demonstrates that the resulting pipeline cannot be replayed.
Worked example
Uses ES2025 features · Script
const pipeline = [1, 2, 3].values().map(n => n * 2).take(2); console.log(JSON.stringify(pipeline.toArray())); console.log(JSON.stringify(pipeline.toArray()));
Expected output
[2,4]
[]
Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.
Common mistake
An iterator is not a reusable array, and a synchronous map callback returning promises does not await them.
Try it yourself
Add a counter inside the callback and compare lazy consumption with eagerly calling Array.map.
Read more: ES2025 specification · MDN explanation and compatibility
Standardized in ES2025 · Built-in method
Set union, intersection, and difference
Set operations express membership relationships directly. union keeps members from either set, intersection keeps shared members, and difference keeps members present only in the receiver. They return new sets.
The receiver is not modified, but object members still use identity-based equality. The ordering rules of a result should not be confused with sorting; sort an explicit array when a report needs a particular order.
The example prints a sorted array for stable display, separating membership calculation from output order.
Worked example
Uses ES2025 features · Script
const left = new Set([1, 2]); const right = new Set([2, 3]); console.log(JSON.stringify([...left.union(right)].sort((a, b) => a - b))); console.log(JSON.stringify([...left.intersection(right)])); console.log(left.size);
Expected output
[1,2,3]
[2]
2
Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.
Common mistake
Set methods do not compare object contents or mutate the receiver. Reversing a difference changes its meaning.
Try it yourself
Compare left.difference(right) with right.difference(left) and explain the two answers.
Read more: ES2025 specification · MDN explanation and compatibility
Standardized in ES2025 · Built-in method
RegExp.escape() inserts literal search text
RegExp.escape prepares text for use as a literal part of a regular-expression pattern. It handles punctuation and boundary cases that simple ad-hoc replacement recipes can miss.
Escaping belongs to a particular destination. A regex-escaped value is not automatically escaped for HTML, a URL, or a shell. Likewise, escaping the search text does not decide whether matching should be case-sensitive or anchored.
The example deliberately adds anchors around the escaped text so the entire input must match. It checks a dot literally rather than treating it as the regex any-character operator.
Worked example
Uses ES2025 features · Script
const input = "a.b"; const pattern = new RegExp(`^${RegExp.escape(input)}$`); console.log(pattern.test("a.b")); console.log(pattern.test("axb"));
Expected output
true
false
Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.
Common mistake
Do not confuse pattern escaping with replacement-string escaping. Each API has its own special characters and rules.
Try it yourself
Try a search value containing brackets or a hyphen. Keep the anchors outside the escaped literal.
Read more: ES2025 specification · MDN explanation and compatibility
Standardized in ES2025 · Built-in async API
Promise.try() captures immediate throws
Promise.try calls a function immediately and converts its return value or thrown exception into a promise outcome. It is useful when a callback may either return a value, return a promise, or throw before returning.
This differs from Promise.resolve(callback()), where the callback is evaluated before Promise.resolve can observe a synchronous throw. It also differs from scheduling the callback in a later then handler: Promise.try invokes it synchronously.
The example catches an immediate failure through the resulting promise and demonstrates the timing with a second log.
Worked example
Uses ES2025 features · Script
const finished = Promise.try(() => { console.log("called"); throw new Error("invalid"); }).catch(error => console.log(error.message)); console.log("after call");
Expected output
called
after call
invalid
Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.
Common mistake
Promise.try does not delay the callback or move it onto another thread. A slow synchronous callback still blocks its current execution.
Try it yourself
Replace the throw with return 4 and observe the value through then. Which log still occurs synchronously?
Read more: ES2025 specification · MDN explanation and compatibility
Recap
Iterator helpers, Set operations, RegExp.escape, and Promise.try add useful building blocks without changing browser support overnight. Check the engines your project supports before adopting new syntax or built-ins.
Read the ES2025 specification →