JavaScript

js/strict-equality

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

drobnastatycznefe-javascript

Dlaczego

== 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.

Poprawka

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.

Przykłady

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

Źródła

Fakty

Identyfikator
js/strict-equality
Waga
drobna
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
jsx html vue svelte astro
Uczy jej skill
fe-javascript JavaScript in the browser
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

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