Skip to content

eslint/no-extra-boolean-cast Correctness

This rule is turned on by default.
🚧 An auto-fix is still under development.

What it does

This rule disallows unnecessary boolean casts.

Why is this bad?

In contexts such as an if statement’s test where the result of the expression will already be coerced to a Boolean, casting to a Boolean via double negation (!!) or a Boolean call is unnecessary.

Example

javascript
var foo = !!!bar;
var foo = Boolean(!!bar);

if (!!foo) {
}
if (Boolean(foo)) {
}

// with "enforceForLogicalOperands" option enabled
if (!!foo || bar) {
}

References

Released under the MIT License.