CKTIS / JavaScript
Bitwise AND (&)
The & operator keeps bits set to 1 in both operands. It is used for masking and testing flags; for Number it operates on signed 32-bit integers, while BigInt results are not limited to 32 bits.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
left & rightleft & right sets a result bit to 1 only when both corresponding input bits are 1; otherwise it sets that bit to 0. For example, 0b1101 & 0b0100 produces 0b0100. A typical use is reading flags through masking.
Operands undergo numeric conversion. For Number, both are then converted to signed 32-bit integers: fractional parts are truncated toward zero, and bits beyond the lowest 32 are not preserved. The result is a Number and can be negative. NaN and infinities are converted to 0.
Two BigInt operands produce a BigInt result without a 32-bit limit, following an unbounded two's-complement model. Mixing Number and BigInt, such as 1 & 1n, throws a TypeError.
Do not confuse & with logical &&: & does not short-circuit and produces a numeric result. To test a single flag, compare the result with zero of the same type: (flags & mask) !== 0 for Number operands or (flags & mask) !== 0n for BigInt operands. Parentheses are necessary because !== has higher precedence than &. For a multibit mask, this test means at least one selected bit is set, not necessarily all of them.
Examples
const flags = 0b1101;
const mask = 0b0100;
console.log(flags & mask);
console.log((flags & mask) !== 0);
console.log(String(13n & 4n));
console.log(4294967296 & 1);Result
4 true 4 0
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.