Bitwise operators

JavaScript has seven bitwise operators. The term bitwise here means to operate on binary numbers. These operators are rarely utilized but are useful to know about nonetheless:

  • Bitwise unsigned right-shift operator: >>>
  • Bitwise left-shift operator: <<
  • Bitwise right-shift operator: >>
  • Bitwise OR: |
  • Bitwise AND: &
  • Bitwise XOR: ^
  • Bitwise NOT: ~ (a unary operator)
Bitwise operations are incredibly rare in JavaScript since you're usually dealing with higher-level sequences of bits like strings or numbers. However, it's worth having at least a cursory understanding of bitwise operations so that if you encounter the need, you can cope.

All bitwise operators in JavaScript will first coerce their operands (or a singular operand, ...

Get Clean Code in JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.