JavaScript = Assignment Operator
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 = yExample
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.
Desktop





Tablets & Mobile





