Mrs. Tini’s stock crates, one crate per bit: & | ^ ~ << >> >>> on your own numbers, the 32 bits the engine really holds, the sign bit, and BigInt beside them…
Why it matters
Rarely for maths, but bit flags are everywhere: permissions (READ | WRITE), features, event masks, colours. And the traps are real: bitwise cuts to 32 signed bits, ~~x is no rounding, and a & b === b does not mean what you think.
The key idea
Bitwise works on 32 signed bits, crate by crate
Common mistakes
Swapping & / | for && / || Very different: & compares bits (180 & 38 is 36), && gives b when a is truthy (180 && 38 is 38). One character changes the meaning.
Relying on ~~x to round It only cuts to 32 bits: ~~-3.7 is -3, and ~~3000000000.7 is -1294967296. Use Math.trunc or Math.floor.
Checking a flag with perm & FLAG === FLAG=== goes first: that is perm & (FLAG === FLAG), which is perm & 1. Write (perm & FLAG) !== 0 with brackets.
Try it in this playground
Compare & and | AND: flags up in both. OR: in either.
~ makes it negative ~180 is -181: bit 31, the sign, flips too.
Go past 32 bits 2147483648 | 0 or ~~3000000000.7: the number is cut and turns negative.
>>> on a negative -8 >>> 1 is 2147483644: the same bits, read with no sign.