Assignment Operators
An assignment operators assigns a value to left operand to the value of the expression on the right.
The Equal Sign
The simplest assignment operator is the equal sign (=
). It is also most commonly used operator as well. All the others assignment operators are variations of the equal sign.
// Using the equal sign to assign value to variable number
let number = 5
// Using the equal sign to change the value of number
number = 3
Arithmetic Assignment Operators
JavaScript has various shorthand operators that can be used to complete arithmetic operations.
let number = 5
// Addition assignment
number += 3 // same as: number = number + 3
// Subtraction assignment
number -= 3 // same as: number = number - 3
// Multiplication assignment
number *= 3 // same as: number = number * 3
// Division assignment
number /= 3 // same as: number = number / 3