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, in the case of bitwise NOT ~) to a 32-bit integer representation. This means that, internally, a number such...