What is the difference between == and === in JavaScript?
Written by Jatin Thacker, Automation Architect · Updated
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 ===.
const str = '100';
const num = 100;
console.log(str == num);
console.log(str === num);
console.log(null === undefined);true false false
const active = '0'. What do active == false and active === false evaluate to?Related questions
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