Skip to content

Files

Latest commit

 

History

History
46 lines (32 loc) · 740 Bytes

no-extra-boolean-cast.md

File metadata and controls

46 lines (32 loc) · 740 Bytes

Pattern: Redundant boolean type cast

Issue: -

Description

In contexts where expression results are automatically coerced to boolean (like if conditions), using explicit boolean casts (!! or Boolean()) is unnecessary. These extra casts make code harder to read without adding any functional benefit.

Examples

Example of incorrect code:

if (!!foo) {
  // ...
}

while (!!bar) {
  // ...
}

const baz = !!!qux;

if (Boolean(foo)) {
  // ...
}

const valid = !!(a && b);

Example of correct code:

if (foo) {
  // ...
}

while (bar) {
  // ...
}

const baz = !qux;

// When explicitly converting to boolean outside of boolean contexts
const bool = Boolean(foo);

const valid = a && b;