Search⌘ K
AI Features

Additional Operators

Explore the use of additional JavaScript operators such as +=, ++, --, &&, and ||. Understand their behavior in conditions and loops, how they affect values, and how to use shortcuts to write efficient, readable code. Learn how to correctly check for NaN values with Number.isNaN().

We will soon write conditions and loops. In these two control structures, a few operators come handy:

  • +=, -=, *=, /=, %= etc. are abbreviations for performing a mathematical operation on a variable. a += 1 is the same as writing a = a + 1.
  • ++x increases the value of x by 1, then returns the increased value
  • x++ returns the original value of x, then increases its value by 1
  • --x decreases the value of x by 1, then returns the decreased value
  • x-- returns the original value of x, then decreases its value by 1

++x and x++

I know the difference between ++x and x++ may not make sense to you right now. I argue that in most cases, it should not even make a difference as long as ...