Modern JavaScript features you can use in Node.js 26
The JavaScript language keeps growing, and a batch of genuinely useful additions is now available unflagged in Node.js 26 and recent browsers. Here are the ones worth reaching for, each run on a stock node:26-slim image so the output is real, not aspirational. (The biggest addition, the Temporal date/time API, has its own post.)
Set operations
Set finally has the methods you always wished it had — no more manual loops or lodash for union and intersection.
const a = new Set([1, 2, 3]);
const b = new Set([3, 4, 5]);
[...a.union(b)]; // [1, 2, 3, 4, 5]
[...a.intersection(b)]; // [3]
[...a.difference(b)]; // [1, 2]
[...a.symmetricDifference(b)]; // [1, 2, 4, 5]
a.isDisjointFrom(new Set([9])); // true
// also: isSubsetOf, isSupersetOfIterator helpers
You can now map, filter, take, and drop directly on iterators — lazily, without materializing arrays at each step. Finish with toArray().
const result = [1, 2, 3, 4, 5]
.values()
.filter((x) => x % 2) // keep odds
.map((x) => x * 10)
.take(2)
.toArray();
console.log(result); // [10, 30]RegExp.escape
Safely escape a string for use inside a regular expression — the long-missing built-in that everyone reimplemented by hand.
RegExp.escape('a.b*c(1)');
// "\x61\.b\*c\(1\)"Note the real output above: RegExp.escape deliberately hex-escapes the first character (here a becomes \x61) so the result is always safe to concatenate, even at the start of a pattern. The metacharacters ., *, and ( are escaped as you'd expect.
Promise.try
Promise.try runs a function and always gives you a promise — whether it returns a value, returns a promise, or throws synchronously. It removes the awkward try/catch-then-Promise.reject dance.
const value = await Promise.try(() => 42);
console.log(value); // 42
// A synchronous throw becomes a rejected promise automatically
Promise.try(() => { throw new Error('boom'); }).catch((e) => console.log(e.message));Array.fromAsync
Build an array from an async iterable (or an iterable of promises) in one call — the async companion to Array.from.
const items = await Array.fromAsync([Promise.resolve('x'), Promise.resolve('y')]);
console.log(items); // ['x', 'y']Float16Array
A typed array for half-precision (16-bit) floats — handy for graphics, ML, and any place memory and bandwidth matter more than precision.
const half = new Float16Array([1.5, 2.25]);
console.log(half.join(',')); // "1.5,2.25"All verified on Node.js 26
Every snippet here was executed on node:26-slim (v26.4.0). Here's the combined run:
$ docker run --rm node:26-slim node features.mjs
union: 1,2,3,4,5
intersection: 3
difference: 1,2
symmetricDiff: 1,2,4,5
RegExp.escape: \x61\.b\*c\(1\)
Promise.try: 42
iterator help: 10,30
Float16Array: 1.5,2.25
fromAsync: x,yThese features are also shipping in recent browsers, but availability varies — check the linked MDN pages before relying on any of them client-side.