Luckily, we only need to understand two bitwise operators to get a grasp on how to use these values for our goal.

“Bitwise Inclusive OR”

The | (“bitwise inclusive or”) is not to be confused with the more commonly used || (“logical or”) operator you may find in “if” statements. Instead, it returns the bits that were set in either one or the other value.

const A = 0b0001;

const B = 0b0010;

const C = 0b0100;

const D = 0b1000; A | B === 0b0011;

A | C | D === 0b1101;

Since each of our original constants has a unique bit, we can combine any amount of these to get a new unique set of bits back, which we can use as a single value.

“Bitwise AND“

Similarly, the & (“bitwise and”) operator is not to be confused with the more commonly used && (“logical and”) operator found in “if” statements. It instead returns the bits that are set in both values.