Skip to content
jshacks.dev
Fundamentals

What Is ES2026 and Every New Feature With Examples

ES2026 adds Array.fromAsync, Error.isError, Math.sumPrecise, Uint8Array base64, Iterator.concat, Map getOrInsert and JSON source text. See fallbacks.

9 min read
Summarize in AI
Flat illustration of an editor window full of code, with the JavaScript, TypeScript, Node.js and npm logos.

An ES edition is a snapshot of what the standards committee finished that year, and the 2026 one is a standard-library edition: seven additions that remove small helpers every project had written for itself. A way to turn an async stream into an array. A way to read a number from JSON without losing digits. A sum that does not drift. The shipping dates differ from engine to engine, so this post treats each feature in the same three parts: what it does, the code you write today in its absence, and how to detect it. The fallbacks run on Node.js 24.1, which is the runtime used for every output here, and the features it already has are shown with their real output. This is where the next edition's features are tracked from; the previous ones are in what was new in ES2025 and ES2024, and the one after is in what is coming in ES2027.

What your runtime has

Before using any of them, ask the runtime. A typeof check per feature is the whole test.

JavaScript
const features = {
  "Array.fromAsync": typeof Array.fromAsync,
  "Error.isError": typeof Error.isError,
  "Math.sumPrecise": typeof Math.sumPrecise,
  "Uint8Array.fromBase64": typeof Uint8Array.fromBase64,
  "Iterator.concat": typeof Iterator.concat,
  "Map#getOrInsert": typeof Map.prototype.getOrInsert,
  "JSON.rawJSON": typeof JSON.rawJSON,
};

for (const [name, type] of Object.entries(features)) {
  console.log(name.padEnd(24), type);
}
Text
Array.fromAsync          function
Error.isError            function
Math.sumPrecise          undefined
Uint8Array.fromBase64    undefined
Iterator.concat          undefined
Map#getOrInsert          undefined
JSON.rawJSON             function

On Node.js 24.1, three of the seven are present (Array.fromAsync, Error.isError and the JSON source text functions) and four are not yet. The table is a snapshot, and your runtime may differ, which is why the habit is to detect and not to assume. A polyfill library such as core-js installs the missing ones, at the cost of bundle size, and a feature check with a handwritten fallback costs less for a feature you use in one place.

Array.fromAsync

Array.fromAsync() is Array.from() for async sources. It accepts an async iterable, a sync iterable of promises, or an array-like, and returns a promise for the array.

JavaScript
async function* pages() {
  for (let page = 1; page <= 3; page++) {
    await Promise.resolve();
    yield { page, items: page * 2 };
  }
}

console.log(await Array.fromAsync(pages()));
console.log(await Array.fromAsync([Promise.resolve("a"), "b", Promise.resolve("c")]));
console.log(await Array.fromAsync(pages(), (entry) => entry.items));
console.log(await Array.fromAsync({ length: 3, 0: "x", 1: Promise.resolve("y"), 2: "z" }));

try {
  await Array.fromAsync([Promise.resolve(1), Promise.reject(new Error("item failed"))]);
} catch (error) {
  console.log(error.message);
}

const manual = [];
for await (const entry of pages()) manual.push(entry);
console.log(manual.length);
Text
[ { page: 1, items: 2 }, { page: 2, items: 4 }, { page: 3, items: 6 } ]
[ 'a', 'b', 'c' ]
[ 2, 4, 6 ]
[ 'x', 'y', 'z' ]
item failed
3

Each source type produced an array, with the promises awaited in order, and a mapping function transformed the items on the way. One rejected item rejected the whole call. The loop at the end is the older way to collect an async iterable, and fromAsync replaces it. It awaits items one after another, so it does not run them in parallel: for a list of promises that are already started, Promise.all is faster. The post on iterators covers the async iteration protocol.

JSON source text access

JSON.parse() turns every number into a double, which loses digits beyond 2^53. The new reviver argument, context.source, holds the original text of a primitive, and JSON.rawJSON() writes a number exactly.

JavaScript
const text = '{"id": 12345678901234567890, "price": 19.50, "name": "order"}';

console.log(JSON.parse(text).id, JSON.parse(text).price);

const exact = JSON.parse(text, (key, value, context) => {
  if (typeof value === "number" && Number.isInteger(value) && !Number.isSafeInteger(value)) {
    return BigInt(context.source);
  }
  if (key === "price") return context.source;
  return value;
});
console.log(exact);

const out = JSON.stringify({ id: JSON.rawJSON("12345678901234567890"), price: JSON.rawJSON("19.50") });
console.log(out);
console.log(JSON.isRawJSON(JSON.rawJSON("1")), JSON.isRawJSON(1));

try {
  JSON.rawJSON("{}");
} catch (error) {
  console.log(error.name);
}
Text
12345678901234567000 19.5
{ id: 12345678901234567890n, price: '19.50', name: 'order' }
{"id":12345678901234567890,"price":19.50}
true false
SyntaxError

The default parse rounded the id and dropped the trailing zero of the price. The reviver read the original text and rebuilt the id as a bigint and kept the price as the string "19.50". JSON.rawJSON() accepts only a valid primitive JSON text, and JSON.stringify writes it verbatim, so the digits survive a round trip. The post on JSON covers the rest of the options, and the large-integer problem is in the post on BigInt.

Error.isError

instanceof Error fails for an error created in another realm, and Object.prototype.toString can be fooled by Symbol.toStringTag. Error.isError(value) returns true only for real error objects, wherever they came from.

JavaScript
import vm from "node:vm";
import { types } from "node:util";

const foreign = vm.runInNewContext("new TypeError('from another realm')");
const impostor = { name: "Error", message: "fake", stack: "fake" };
const tagged = { [Symbol.toStringTag]: "Error" };

const isError = (value) =>
  typeof Error.isError === "function" ? Error.isError(value) : types.isNativeError(value);

console.log(foreign instanceof Error, isError(foreign));
console.log(isError(new RangeError("local")), isError(impostor));
console.log(Object.prototype.toString.call(tagged), isError(tagged));
console.log(isError(null), isError("Error"));
Text
false true
true false
[object Error] false
false false

The helper prefers the new function, which Node.js 24.1 has, and falls back to Node.js's util.types.isNativeError where it is missing, which does the same job. The foreign error fails instanceof and passes the real check, and an object that only looks like an error is rejected, as is one that merely claims the tag. The post on realms explains why instanceof breaks. In browser code with no util, a fallback of "has a string message and stack" is the usual approximation.

Math.sumPrecise

Summing floats accumulates rounding error. Math.sumPrecise(iterable) adds the exact values and rounds once at the end.

JavaScript
const values = [0.1, 0.2, 0.3];

console.log(values.reduce((sum, n) => sum + n, 0));

function compensatedSum(numbers) {
  let sum = 0;
  let compensation = 0;
  for (const value of numbers) {
    const next = sum + value;
    compensation += Math.abs(sum) >= Math.abs(value) ? sum - next + value : value - next + sum;
    sum = next;
  }
  return sum + compensation;
}

const sumPrecise = Math.sumPrecise ?? compensatedSum;

console.log(sumPrecise(values));
console.log(sumPrecise([1e20, 1, -1e20]), [1e20, 1, -1e20].reduce((s, n) => s + n, 0));
console.log(sumPrecise([]));
Text
0.6000000000000001
0.6
1 0
0

The naive sum came out as 0.6000000000000001, and the compensated sum, which the new function is specified to match or beat, returned 0.6. The third line shows the hard case: with a large value and its negative, the naive sum loses the 1 completely and returns 0, where an exact sum returns 1. The fallback in this post is the Neumaier variant of compensated summation, which handles that, and the built-in is exact for any input. For money, integers in cents remain the right tool, as in the post on 0.1 plus 0.2.

Base64 and hex on Uint8Array

Binary-to-text conversion was missing from the language, so browsers used btoa with workarounds and Node.js used Buffer. The new methods put it on Uint8Array itself.

JavaScript
// The new API, on runtimes that have it:
// new Uint8Array([72, 105]).toBase64();      // "SGk="
// Uint8Array.fromBase64("SGk=");              // Uint8Array [72, 105]
// new Uint8Array([72, 105]).toHex();          // "4869"
// Uint8Array.fromHex("4869");                 // Uint8Array [72, 105]

const bytes = new Uint8Array([72, 105, 255, 0]);

const toBase64 = (array) =>
  typeof array.toBase64 === "function" ? array.toBase64() : Buffer.from(array).toString("base64");
const toHex = (array) =>
  typeof array.toHex === "function" ? array.toHex() : Buffer.from(array).toString("hex");
const fromBase64 = (text) =>
  typeof Uint8Array.fromBase64 === "function"
    ? Uint8Array.fromBase64(text)
    : new Uint8Array(Buffer.from(text, "base64"));

console.log(toBase64(bytes), toHex(bytes));
console.log(fromBase64("SGn/AA=="));
console.log(toBase64(new Uint8Array([251, 255])), Buffer.from([251, 255]).toString("base64url"));
Text
SGn/AA== 4869ff00
Uint8Array(4) [ 72, 105, 255, 0 ]
+/8= -_8

The fallbacks use Buffer and produce the same strings. The new methods are toBase64(), fromBase64(), toHex() and fromHex(), with options for the URL-safe alphabet and for padding, and setFromBase64() to decode into an existing array without allocating. They are the standard replacement for btoa(String.fromCharCode(...bytes)), which breaks on large arrays. The typed arrays post covers the type they extend.

Iterator.concat

Iterator.concat(...iterables) joins several iterables into one lazy iterator, in order.

JavaScript
function* concat(...iterables) {
  for (const iterable of iterables) yield* iterable;
}

const joined = Iterator.concat ?? ((...its) => Iterator.from(concat(...its)));

const pipeline = joined([1, 2], new Set([3]), "ab", (function* () { yield 4; })())
  .map((item) => String(item).toUpperCase())
  .toArray();

console.log(pipeline);

const lazy = joined([1, 2, 3], [4, 5, 6]).filter((n) => n % 2 === 0).take(2);
console.log([...lazy]);
Text
[ '1', '2', '3', 'A', 'B', '4' ]
[ 2, 4 ]

The fallback is a generator with yield*, wrapped with Iterator.from so that the helper methods from ES2025 are available on the result. Items from arrays, sets, strings and generators came out in order, and because the pipeline is lazy, the second example stops reading after two matches. The built-in does the same without the wrapper.

Map getOrInsert

The get-or-create pattern is everywhere: read a key, and if it is missing, store a default and use it. getOrInsert(key, value) does it in one call, and getOrInsertComputed(key, fn) builds the default only when needed.

JavaScript
function getOrInsert(map, key, value) {
  if (typeof map.getOrInsert === "function") return map.getOrInsert(key, value);
  if (!map.has(key)) map.set(key, value);
  return map.get(key);
}

function getOrInsertComputed(map, key, make) {
  if (typeof map.getOrInsertComputed === "function") return map.getOrInsertComputed(key, make);
  if (!map.has(key)) map.set(key, make(key));
  return map.get(key);
}

const groups = new Map();
for (const word of ["apple", "avocado", "banana", "blueberry", "cherry"]) {
  getOrInsert(groups, word[0], []).push(word);
}
console.log(groups);

let built = 0;
const cache = new Map();
const first = getOrInsertComputed(cache, "k", (key) => (built++, { key }));
const second = getOrInsertComputed(cache, "k", (key) => (built++, { key }));
console.log(first === second, built);
Text
Map(3) {
  'a' => [ 'apple', 'avocado' ],
  'b' => [ 'banana', 'blueberry' ],
  'c' => [ 'cherry' ]
}
true 1

The first block grouped words by initial letter without a separate existence check, and the second built each value once. With the built-in, groups.getOrInsert(word[0], []).push(word) is the one-line form. The computed variant matters when constructing the default is costly, since getOrInsert evaluates its argument every time, as the plain call getOrInsert(groups, word[0], []) allocates an array on every iteration even when it is not used.

Which to adopt first

Start with the two that run today. Array.fromAsync replaces a collection loop with one call and has no cost to adopt on Node.js 24, and JSON source text access fixes a long-standing data loss in places where ids exceed 2^53. For the other five, write the fallback once in a small module, import it everywhere, and delete it when your minimum runtime ships the feature. A single module with the fallbacks is easier to remove than the same code inlined across a project.

Where to be careful

Do not assume a feature because the edition is named. An edition's finalization date is not a shipping date, and engines implement proposals as they reach the later stages, so a feature can exist in one browser and not another for a year. Do not use Array.fromAsync on sources that must run concurrently, since it awaits one item at a time. And treat context.source as available only for primitives: the reviver receives it for numbers, strings, booleans and null, and objects and arrays have none.

The features are defined in the ECMAScript specification and the proposals repository, and MDN's pages on Array.fromAsync and JSON.parse document the two that ship broadly.

Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.