Loading lesson path
Concept visual
Start at both ends
Assignment operators assign values to JavaScript variables.
Formula
Given that x = 10 and y = 5, the table below explains the assignment operators:=
Formula
x = y x = y x = 5+=
Formula
x += y x = x + y x = 15-=
Formula
x -= y x = x - y x = 5*=
Formula
x *= y x = x * y x = 50**=
Formula
x **= y x = x ** y x = 100000/=
Formula
x /= y x = x / y x = 2%=
Formula
x %= y x = x % y x = 0Formula
x: 45 size.x = 45 x = 45&&=
Formula
true &&= 10 x = 10||=
Formula
false ||= 10 x = 10??=
Formula
null ??= 10 x = 10
The = OperatorSimple Assignment Operator assigns a simple value to a variable.
Simple Assignment Examples let x = 10;
let x = 10 + y;
The += OperatorAddition Assignment Operator adds a value to a variable.
Addition Assignment Examples let x = 10;
x += 5;
The -= OperatorSubtraction Assignment Operator subtracts a value from a variable.
let x = 10;
x -= 5;
The *= OperatorMultiplication Assignment Operator multiplies a variable.
let x = 10;
x *= 5;
The **= OperatorExponentiation Assignment Operator raises a variable to the power of the operand.
let x = 10;
x **= 5;
The /= OperatorDivision Assignment Operator divides a variable.
let x = 10;
x /= 5;
The %= OperatorRemainder Assignment Operator assigns a remainder to a variable.
let x = 10;
x %= 5;Two assignment operators can assign values to strings:
Simple Assignment Operator assigns a simple value to a string.
Addition Assignment Operator adds a value to a string.
Formula
The = Operator