JavaScript & Bitwise AND Operator
The bitwise AND operator (&) compares the bits of two integers and sets each bit to 1 only where both have a 1. It's used for flags and masks.
Description
The bitwise AND operator & converts both operands to 32-bit integers and returns a number whose bits are 1 only where both operands have a 1. It's used to test flags packed into one number, and n & 1 is a quick odd-number check. Don't confuse it with the logical &&.
All bitwise operators work on 32-bit signed integers: decimals are truncated and numbers outside that range wrap around, so they aren't suitable for large values. BigInts are supported if both operands are BigInts, with no size limit.
Bit flags let you store several on/off options in one number, which is compact and fast to test, and appear in some web APIs, such as Node.compareDocumentPosition(). In everyday code, an object of booleans or a Set of option names is usually easier to read.
Properties
- Operator
&- Category
- Bitwise
- Precedence
- 7 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
x & yExample
Browser Support
The following information will show you the current browser support for the & operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





