Favorites

JavaScript [a, b] = Destructuring assignment Operator

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
[a, b] =
JavaScript Assignment OperatorThis operator is supported by all modern browsers.
Updated 28th November 2026

Destructuring assignment unpacks values from arrays or properties from objects into separate variables in a single statement.

Description

Destructuring lets you unpack values from arrays, or properties from objects, into distinct variables using a pattern that mirrors the data's shape. Array patterns use position, const [first, second] = list; object patterns use property names, const { name, age } = user.

Patterns can rename ({ name: userName }), give defaults ({ size = 'm' }), skip items ([, second]), collect the rest ([head, ...tail]) and nest. Destructuring also works in function parameters and for...of loops, and swapping two variables is as simple as [a, b] = [b, a].

Destructuring a value that is null or undefined throws a TypeError, so give a default for optional objects, as in const { a } = options ?? {}, or a parameter default, function f({ a } = {}). When assigning to existing variables with an object pattern, wrap the whole statement in parentheses, ({ a, b } = obj), so the braces aren't read as a block.

Properties

Operator
[a, b] =
Category
Assignment
Precedence
2 (1 is lowest, 18 is highest)
Associativity
right-to-left

Syntax

const [a, b] = array;
const { name, age } = object;
const { name: alias = defaultValue, ...rest } = object;

Example

const [first, , third = 'default'] = ['a', 'b'];
console.log(first, third);

const user = { name: 'Sam', role: 'admin', age: 30 };
const { name, role: job, ...rest } = user;
console.log(name, job, rest);

let x = 1, y = 2;
[x, y] = [y, x];
console.log(x, y);

function show({ title, size = 'm' }) { return title + ' (' + size + ')'; }
console.log(show({ title: 'Shirt' }));

Browser Support

The following information will show you the current browser support for the [a, b] = operator. Hover over a browser icon to see the version that first introduced support for this operator.

This operator is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee