"use strict" opts into a restricted variant that catches silent errors.
"use strict";x = 10; // ReferenceError — undeclared variableforEach, map, filter, reduce, some, every, indexOf added to Array.prototype.
[1, 2, 3].map(n => n * 2); // [2, 4, 6][1, 2, 3].filter(n => n > 1); // [2, 3]Native JSON.parse() and JSON.stringify() built into the language.
JSON.stringify({ a: 1 }); // '{"a":1}'JSON.parse('{"a":1}'); // { a: 1 }Object.create, Object.keys, Object.defineProperty, Object.freeze introduced.
const obj = Object.create(null); // no prototypeObject.keys({ a: 1, b: 2 }); // ['a', 'b']Block-scoped variable declarations replacing the pitfalls of var.
let x = 1;const PI = 3.14;Concise syntax with lexical this binding.
const double = n => n * 2;Syntactic sugar over prototype-based inheritance.
class Animal { constructor(name) { this.name = name; } }String interpolation and multi-line strings with backticks.
const msg = `Hello, ${name}!`;Concise patterns for extracting and combining data.
const { a, b } = obj;const arr = [...a, ...b];Native asynchronous abstraction replacing callback hell.
fetch('/api').then(r => r.json()).catch(console.error);Static module system with named and default exports.
import { add } from './math.js';export default function main() {}New built-in collection types.
const s = new Set([1, 2, 2]); // {1, 2}Unique, immutable primitive for non-colliding property keys.
const id = Symbol('id');Custom iterable protocol and pausable function execution.
function* gen() { yield 1; yield 2; }Intercept and redefine fundamental object operations.
const p = new Proxy(target, { get(obj, key) { ... } });Concise power operator.
2 ** 10; // 1024Check if an array contains a value (handles NaN correctly, unlike indexOf).
[1, NaN, 3].includes(NaN); // trueSyntactic sugar over Promises for sequential async code.
async function load() { const data = await fetch('/api').then(r => r.json()); return data;}Iterate over object key-value pairs or values directly.
Object.entries({ a: 1, b: 2 }); // [['a',1],['b',2]]Pad strings to a target length.
'5'.padStart(3, '0'); // '005'Trailing commas now allowed in function parameter and argument lists.
function f(a, b,) {} // validSpread and rest operators extended to object literals.
const { a, ...rest } = { a: 1, b: 2, c: 3 };const merged = { ...obj1, ...obj2 };Run cleanup code after a promise settles regardless of outcome.
fetch('/api').then(handle).catch(log).finally(cleanup);for-await-of loop and async generators for async data streams.
for await (const chunk of stream) { process(chunk); }Named regex groups for readable captures.
const { year, month } = '2024-05'.match(/(?<year>\d{4})-(?<month>\d{2})/).groups;Flatten nested arrays and map+flatten in one pass.
[[1, 2], [3]].flat(); // [1, 2, 3][1, 2, 3].flatMap(n => [n, n]); // [1,1,2,2,3,3]Convert key-value pairs back into an object (inverse of Object.entries).
Object.fromEntries([['a', 1], ['b', 2]]); // {a:1, b:2}Trim whitespace from a specific end of a string.
' hi '.trimStart(); // 'hi 'Omit the error parameter in catch when not needed.
try { ... } catch { /* no (err) required */ }Safely navigate nested object properties without null checks.
user?.address?.city ?? 'Unknown'Default values only for null/undefined (not other falsy values).
const port = config.port ?? 3000;Resolves when all promises settle, returning status + value/reason for each.
const results = await Promise.allSettled([p1, p2]);Arbitrary-precision integers beyond Number.MAX_SAFE_INTEGER.
const big = 9007199254740993n; // note the n suffixLazy-load ES modules on demand.
const { add } = await import('./math.js');Universal reference to the global object across environments.
globalThis.fetch; // works in browser and Node.jsCombine logical operators with assignment.
cache[key] ??= compute(key);user.name ||= 'Anonymous';Resolves with the first fulfilled promise; rejects if all reject.
const fastest = await Promise.any([mirror1, mirror2]);Replace all occurrences without a regex.
'aabbcc'.replaceAll('b', 'x'); // 'aaxxcc'Underscores as visual separators in numeric literals.
const billion = 1_000_000_000;Weakly hold object references and register cleanup callbacks.
const ref = new WeakRef(target);ref.deref()?.method();Declare instance fields and private members directly in the class body.
class Counter { #count = 0; inc() { this.#count++; }}Use await at the top level of ES modules without an async wrapper.
const data = await fetch('/api').then(r => r.json());Access elements by index with negative index support.
[1, 2, 3].at(-1); // 3Safe replacement for hasOwnProperty.
Object.hasOwn(obj, 'key'); // true/falseChain errors with a cause property for better diagnostics.
throw new Error('Load failed', { cause: originalError });Search from the end of an array.
[1, 2, 3, 2].findLast(n => n === 2); // 2 (last match)Non-mutating versions of sort, reverse, splice, and index assignment.
const sorted = arr.toSorted(); // arr unchangedconst updated = arr.with(1, 99); // new array, index 1 = 99Shebangs (#!) at the start of scripts are now part of the spec.
#!/usr/bin/env nodeSymbols can now be used as WeakMap keys.
const wm = new WeakMap();wm.set(Symbol('key'), value);Create a promise with its resolve/reject exposed — cleaner than the constructor pattern.
const { promise, resolve, reject } = Promise.withResolvers();setTimeout(resolve, 1000, 'done');Group iterables by a key function without a manual reduce.
const grouped = Object.groupBy(items, item => item.type);// { 'fruit': [...], 'veggie': [...] }Move ownership of an ArrayBuffer to a new one, detaching the old.
const newBuf = buf.transfer(newByteLength);Enhanced Unicode regex with set notation and string properties.
/[\p{Decimal_Number}--[0-9]]/v.test('٢'); // true