Bitwise operators are one of the most powerful but often misunderstood topics in JavaScript. They allow you to work with numbers at the binary (bit) level, which can be very useful in performance optimization, data processing, and advanced programming tasks.
Bitwise operators work directly on the binary representation (0s and 1s) of numbers.
Instead of treating numbers like 5 or 10 normally, JavaScript converts them into binary first:
Example:
5 → 00000101 3 → 00000011
Then the operation is performed bit by bit.
Why Learn Bitwise Operators?
Bitwise operations are used in:
-
Performance optimization
-
Graphics programming
-
Encryption and security
-
Working with permissions (flags)
-
Competitive programming
-
Low-level data manipulation
Even though they are advanced, understanding the basics gives you a strong edge.
| Operator | Name |
|---|---|
& | AND |
| ` | ` |
^ | XOR |
~ | NOT |
<< | Left Shift |
>> | Right Shift |
>>> | Zero-fill Right Shift |
Output :
a & b = 1
a | b = 7
a ^ b = 6
~a = -6
a << 1 = 10
a >> 1 = 2
Bitwise operators in JavaScript allow you to work directly with binary data and perform highly efficient operations. While they are more advanced than typical JavaScript topics, learning the basics gives you deeper insight into how JavaScript handles numbers internally.