Favorites

JavaScript = Assignment Operator

☕
Enjoying this site?

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

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

The assignment operator (=) stores a value in a variable or property. It returns the assigned value, so assignments can be chained.

Description

The assignment operator = assigns the value of its right operand to the variable, property or element on its left. The expression itself evaluates to the assigned value, and the operator is right-associative, so a = b = 5 sets both. Assigning to a const throws a TypeError.

Don't confuse = with the comparison operators == and ===; writing if (x = 5) assigns rather than compares, and is always truthy. With destructuring, one assignment can unpack several values at once.

Assignment to an undeclared variable creates a global variable in non-strict code, which is a common source of bugs; strict mode, modules and classes throw a ReferenceError instead. Assigning an object or array to another variable copies the reference, not the contents, so both variables point to the same object; use spread syntax or structuredClone() to make copies.

Properties

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

Syntax

x = y

Example

let a, b;
a = b = 5;
console.log(a, b);

const user = {};
user.name = 'Sam';
console.log(user);

let [first, second] = ['x', 'y'];
console.log(first, second);

Browser Support

The following information will show you the current browser support for the = 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