Assignment Operators
JavaScript Assignments
Assignment operators assign values to variables.
Given that x = 10 and y = 5, the table below explains the assignment operators:
Oper | Example | Same As | Result | |
---|---|---|---|---|
= | x = y | x = y | x = 5 | Try it » |
+= | x += y | x = x + y | x = 15 | Try it » |
-= | x -= y | x = x - y | x = 5 | Try it » |
*= | x *= y | x = x * y | x = 50 | Try it » |
/= | x /= y | x = x / y | x = 2 | Try it » |
%= | x %= y | x = x % y | x = 0 | Try it » |
: | x: 45 | size.x = 45 | x = 45 | Try it » |
Logical Assignment Operators
Oper | Example | Result | |
---|---|---|---|
&&= | true &&= 10 | x = 10 | Try it » |
||= | false ||= 10 | x = 10 | Try it » |
??= | null ??= 10 | x = 10 | Try it » |
The Spread (...) Operator
The ...
operator splits iterables into individual elements.
Syntax | Example | |
---|---|---|
const myArr = [1, 2, 3]; | let xMin = Math.min(...myArr); | Try it » |
Learn More:
Study our JavaScript Assignment Tutorial.