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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.