What is the difference between == and ===, and what are the falsy values in JavaScript?
=== is strict equality: if the two operands are of different types the result is false, with no conversion. == is loose equality: it coerces the operands to a common type first, following a set of rules that produce genuinely surprising results.
0 == '0'is true,0 === '0'is false.null == undefinedis true, butnull == 0is false —nullis loosely equal only toundefinedand itself.NaNis not equal to anything, including itself. UseNumber.isNaNto test for it.
The eight falsy values — everything else is truthy:
false,0,-0,0n,'',null,undefined,NaN
Note: An empty array and an empty object are both truthy, which catches people out constantly. The one place == is genuinely useful is x == null, which tests for null or undefined in a single check — and the modern alternatives are the ?? and ?. operators.





