Why this matters
Loose equality (==) can cause unexpected behavior due to type coercion. Always use strict equality (===) to prevent logical errors.
Ensure that strict equality (===) is used instead of loose equality (==). Loose equality can lead to unexpected type coercion and logical errors.
Loose equality (==) can cause unexpected behavior due to type coercion. Always use strict equality (===) to prevent logical errors.
Side-by-side examples engineers can pattern-match during review.
if (userInput == 0) {
console.log('This might cause type coercion vulnerabilities');
}if (userInput === 0) {
console.log('This avoids type coercion issues');
}if (userInput == 0) {
console.log('This might cause type coercion vulnerabilities');
}if (userInput === 0) {
console.log('This avoids type coercion issues');
}From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.