Skip to content

Files

Latest commit

 

History

History
31 lines (23 loc) · 576 Bytes

File metadata and controls

31 lines (23 loc) · 576 Bytes

Pattern: Use of non-strict equality operator

Issue: -

Description

Using non-strict equality operators (== and !=) can lead to hard-to-track bugs due to type coercion. Strict equality operators (=== and !==) are safer as they check both value and type.

Examples

Example of incorrect code:

let a = [];
let b = false;
a == b;  // evaluates to true due to type coercion

if (x != null) {
  // ...
}

Example of correct code:

let a = [];
let b = false;
a === b;  // evaluates to false as expected

if (x !== null) {
  // ...
}