The single most useful fact about JavaScript's == is that it
breaks a rule arithmetic never breaks. Run in Node 25 on 2026-09-02:0 == "" is true, 0 == "0" is true, and"" == "0" is false. Equality that is not transitive cannot be
reasoned about, only looked up, which is the argument for=== and the reason no table of this kind is worth memorising.
Two more rows from the same run are worth having by name.null == undefined is true and they are equal to nothing else, not
even 0, which makes x == null the one deliberate use of loose
equality: it asks is this null or undefined and nothing more. And[] == false is true, so an empty array is loosely equal to false
while being truthy in an if, which are two different questions the
language answers differently.
The type system in four answers
typeof null is object, a bug from 1995 that cannot
be fixed without breaking the web. typeof [] is alsoobject, so arrays are tested withArray.isArray([]), which is true. typeof NaN isnumber, which is correct and unhelpful, andNaN == NaN is false while Object.is(NaN, NaN) is true.
Four checks, four different tools, and typeof is the right one for
exactly two of them.
Seven values, measured in Node 25
Which pairs == calls equal
Read any two rows against each other: the grid is symmetric and it is not transitive, which is the property that makes it unusable as a rule.
1 where a == b, 0 where it does not. Node 25, 2026-09-02.
The null and undefined rows are the only two that behave: they match each other and nothing else, which is what makes x == null the one loose comparison worth writing. Every other row is a reason to use ===.
Interactive Practice Lab
Edit and run this snippet directly in your browser (zero setup)
const scores = [78, 92, 64, 95, 88];const passed = scores.filter((n) => n >= 70);const avg = passed.reduce((a, b) => a + b, 0) / passed.length;console.log('Passed count:', passed.length);console.log('Average score:', avg.toFixed(1));Live Big-O Complexity & Binary Search Race Lab
Compare complexity curves at scale and watch Linear vs Binary Search race live.
The loop variable, and the method that forgets what it belongs to
Closures over var capture one shared binding, so three functions
built in a loop all answer the final value: var gives[ 3, 3, 3 ] and let gives [ 0, 1, 2 ],
because let makes a new binding each iteration. This is the whole
reason let exists and it is the one difference worth being able to
state.
Binding rules in practice
Where loop variables and method this break or hold
Both loop closures and object methods fail silently when they share or lose their binding, and both have direct modern fixes.
Loop closures
- Three callbacks read final value
- Returns [3, 3, 3]
- Each callback captures its own step
- Returns [0, 1, 2]
Method this
- Assigned method prints dock undefined
- Object arrow method has no enclosing this
- dock.label() prints dock D1
- Arrow callback keeps outer this
Use let for loop counters, keep regular methods on objects, and save arrows for callbacks.
this is decided at the call, not at the definition.dock.label() answers dock D1. Assign that same method
to a name and call it, and it answers dock undefined, because
nothing to the left of the dot means nothing bound. bind fixes it,
and an arrow function is the modern answer for a callback because it takesthis from where it was written. The trap is the mirror image:
an arrow used as an object's own method answersdock undefined too, because there is no enclosing object to takethis from.
What to run in 2026
TypeScript is the answer to most of this page, free and open source, and as
of 2026 it is the default for anything past a single file. Its comparison rules
refuse 0 == "" outright rather than explaining it, and thetypeof null problem is handled in the type system instead of at
runtime. It replaced writing the checks by hand and hoping, which is what every
paragraph above describes.
Static checks to run
What TypeScript and ESLint filter out before runtime
Rather than memorizing every quirk by hand at four in the afternoon, static tooling rejects unsafe comparisons and var leaks upfront.
- TypeScript compiler+Cross-type comparisons like 0 == "" and unchecked typeof null branches→Consistent type checks handled before code runs
- ESLint eqeqeq rule+Accidental == coercions across plain JavaScript files→Strict === everywhere with an intentional exception for x == null
- ESLint no-var rule+Function-scoped var declarations that share one loop slot→Block-scoped let and const bindings per iteration
TypeScript covers multi-file codebases by default, while ESLint protects plain JavaScript with two targeted rules.
ESLint is the one for a codebase that stays plain JavaScript, also free, and
as of 2026 still the standard. Two rules cover the ground here: eqeqeq bans== with an exception for x == null, and no-var bans the
declaration that produced [ 3, 3, 3 ]. It replaced knowing all of
this and remembering it at four in the afternoon.
Where this stalls people
The stall is that none of this fails loudly. Every line above runs, returns a
value and moves on, so a mistake becomes a wrong number in a report rather than
an error with a line number. People arriving from a language that raises get
caught by this once and conclude that JavaScript is unpredictable; it is
predictable, and the rules are simply not the ones anywhere else uses.
Why mistakes slip through
Silent wrong values on the surface, three rules underneath
JavaScript keeps executing instead of raising an error with a line number, so three daily habits do most of the prevention work.
- Wrong number in a reportEvery expression returns a value and moves on silently
- Avoid == except against nullPrevents non-transitive coercion surprises
- Never declare with varPrevents shared closure state across loop iterations
- Arrows for callbacks, not methodsKeeps method this bound to its owning object
Adopting those three habits eliminates the silent bugs that make newcomers think the language is unpredictable.
The habit that removes most of it in a day: never write ==
except against null, never write var, and use an arrow
for every callback and never for a method. Those three cover the whole of this
page. Where the values then go once they reach a page is
reading and changing the
page from script, what happens when a value arrives later than the line
asking for it is
callbacks,
promises and await, and the checker is
types on top of
JavaScript, and what they catch, all under
the only language a browser
runs.