JavaScript

js/strict-equality

Compare with === and !==; loose == and != convert types first (x == null as a deliberate null-or-undefined test is the exception).

minorstaticfe-javascript

Why

== converts both sides before comparing, so "0" == 0, "" == 0 and [] == false are all true. A value read from a form field or a URL is a string, and a loose comparison with a number quietly passes or fails for the wrong reason.

Fix

Use === and !==, and convert explicitly where the types differ (Number(input.value) === 3). Keep x == null only where you mean "null or undefined", or write x === null || x === undefined.

Examples

// bad
if (params.get('page') == 1) showFirst()
// good
if (Number(params.get('page')) === 1) showFirst()

Sources

Facts

Id
js/strict-equality
Severity
minor
Check
static checked in the source by audit
Applies to
jsx html vue svelte astro
Taught by the skill
fe-javascript JavaScript in the browser
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain js/strict-equality