Skip to contentPlayForge

What is the difference between == and === in JavaScript?

Written by Jatin Thacker, Automation Architect · Updated

=== (strict equality) checks that both value and type are identical without coercion. == (loose equality) converts operands to a common type before comparing them, producing unexpected matches.

This answer is one piece of Chapter 1: Values and Variables.

In JavaScript, equality checks come in two varieties: strict (=== and !==) and loose (== and !=). Strict equality compares two values without type conversion: if the operand types differ, the comparison returns false immediately.

Loose equality (==) performs implicit type coercion when comparing operands of different types. For example, '42' == 42 evaluates to true because JavaScript converts the string into a number. It also leads to counter-intuitive cases where false == 0 is true and null == undefined is true.

In test automation, loose equality is a frequent source of false-positive checks. Text retrieved from the DOM is always a string. Comparing '0' == false passes with loose equality but masks a logic defect. Modern test code standardizes strictly on ===.

strict-equality.mjs(node)
const str = '100'; const num = 100; console.log(str == num); console.log(str === num); console.log(null === undefined);
Output
true
false
false
Test yourself
You read a discount code status from the page: const active = '0'. What do active == false and active === false evaluate to?

AI can write the test now. The job is knowing whether it checks anything. That's what the course teaches, one chapter at a time.

163 lessons · 226 drills · start free

← All questions

Training a team? Talk to us.