Skip to content

noBitwiseOperators

Disallow bitwise operators.

The use of bitwise operators in JavaScript is very rare and often & or | is simply a mistyped && or ||, which will lead to unexpected behavior.

let x = y | z;
code-block.js:1:9 lint/nursery/noBitwiseOperators ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of ’|‘.

> 1 │ let x = y | z;
^^^^^
2 │

Did you mean || instead? If you want to use the bitwise operator, consider suppressing this diagnostic.

x |= y;
code-block.js:1:1 lint/nursery/noBitwiseOperators ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of ’|=‘.

> 1 │ x |= y;
^^^^^^
2 │

Bitwise operators are prohibited because their use can be confusing or unintended. If you did want to use the bitwise operator, consider suppressing this diagnostic.

let x = y || z;
let x = y && z;

The rule provides the options described below.

Allows a list of bitwise operators to be used as exceptions.

{
"options": {
"allow": ["&", "|", "^", "~", "<<", ">>", ">>>"]
}
}
biome.json
{
"linter": {
"rules": {
"nursery": {
"noBitwiseOperators": "error"
}
}
}
}