JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)
What are the bitwise operators available in javascript
Below are the list of bitwise logical operators used in JavaScript
- Bitwise AND ( & )
- Bitwise OR ( | )
- Bitwise XOR ( ^ )
- Bitwise NOT ( ~ )
- Left Shift ( << )
- Sign Propagating Right Shift ( >> )
- Zero fill Right Shift ( >>> )
Practical Code Example
javascript
// Bitwise Operators manipulate 32-bit binary representations:
const READ = 1; // 0001
const WRITE = 2; // 0010
const EXECUTE = 4; // 0100
let permission = READ | WRITE; // 0011 (Bitwise OR: combine flags)
console.log((permission & READ) !== 0); // true (Bitwise AND: test flag)
console.log((permission & EXECUTE) !== 0); // false