Variable holds value, and this value is assigned to a variable using assignment operator (= equals to). Assignment operator assigns a value to a variable.

Variable is always in left hand side and equals to in middle and value, variable is in right hand side of javascript statement.

Syntax

variable_name = value | variable
<script>
let a = 60; // assigned value to variable a
let b = 20; // assigned value to variable b

 a = b; // assigned a variable b to variable a
</script>

Assign value to a variable

<script>
let a = 60;
</script>

In above example. variable a is assigned with value 60, using = (assignment operator) equals to.

Assignment operator with arithmetic operators

JavaScript allows to use arithmetic operators with Assignment operator, below is the list.

Operator NameOperatorExpressionSimilar to
Addition Assignment Operator +=a+=ba = a+b
Subtraction Assignment Operator-=a-=ba = a-b
Multiplication Assignment Operator*=a*=ba = a*b
Exponentiation Assignment Operator/=a/=ba = a/b
Division Assignment Operator%=a%=ba = a%b
Remainder Assignment Operator**=a**=ba = a**b

Shift Assignment Operators

Operator NameOperatorExpressionSimilar to
Left shift Assignment Operator<<=a <<= ba = a << b
Right shift Assignment Operator>>=a >>= ba = a >> b
Unsigned right shift Assignment Operator>>>=a >>>= ba = a >>> b

Bitwise Assignment Operators

Operator NameOperatorExpressionSimilar to
AND Assignment Operator&=a &= ba = a & b
OR Assignment Operator^=a ^= ba = a ^ b
NOT Assignment Operator|=a |= ba = a | b

Logical Assignment Operators

Operator NameOperatorExpressionSimilar to
logical and Assignment Operator&&=a &&= ba = a && (a = b)
logical or Assignment Operator||=a ||= ba = a || (a = b)
logical not Assignment Operator??=a ??= ba = a ?? (a = b)