Assignment Operators
JavaScript Assignment Operators
Assignment operators are used to assign values to JavaScript variables.
Given that x = 10 and y = 5, the table below explains the assignment operators:
Oper | Example | Same As | Result | Try it |
---|---|---|---|---|
= | 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 » |
Learn More:
Study our JavaScript Assignment Tutorial.
Browser Support
Assignment Operators
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
The Nullish Coalescing Operator (??)
The ??
operator returns the first argument if it is not nullish
(null
or undefined
).
Otherwise it returns the second argument.
The nullish operator is supported in all browsers since March 2020:
Chrome 80 | Edge 80 | Firefox 72 | Safari 13.1 | Opera 67 |
Feb 2020 | Feb 2020 | Jan 2020 | Mar 2020 | Mar 2020 |