What is the difference between == and === in JavaScript?
Suggested answer
=== (strict equality): Compares both value and type — no type coercion. 1 === '1' is false (number vs string). null === undefined is false. == (loose equality): Performs type coercion before comparison. Follows the Abstract Equality Comparison algorithm. Examples of counterintuitive results: 0 == '' is true (both coerce to 0 vs false, then number 0), null == undefined is true, false == '0' is true. Always use === to avoid coercion surprises. Similarly, !== vs !=. Special case: NaN === NaN is false — use Number.isNaN(value) to check for NaN. Object.is(a, b) handles NaN and +0/-0 correctly, unlike ===. In LWC and Apex, always use strict equality comparisons in JavaScript.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.