Advanced Operators
When operators are put together without parenthesis, the order in which they are applied is determined by the precedence of the operators. Multiplication (*)
and division (/)
has higher precedence than addition (+)
and subtraction (-)
.
Some advanced operators can be used, such as:
Modulus (division remainder):
x = y % 2
Exponential: Given a= 5,
c = a**2
, Results: c= 25Increment: Given a = 5
c = a++
, Results: c = 5 and a = 6c = ++a
, Results: c = 6 and a = 6
Decrement: Given a = 5
c = a--
, Results: c = 5 and a = 4c = --a
, Results: c = 4 and a = 4
Nullish coalescing operator '??'
The nullish
coalescing operator returns the first argument if it's not null/undefined
, else the second one. It is written as two question marks ??
. The result of x ?? y
is:
if
x
is defined, thenx
,if
y
isn’t defined, theny
.
Last updated
Was this helpful?