Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

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 == undefined is true, but null == 0 is false — null is loosely equal only to undefined and itself.
  • NaN is not equal to anything, including itself. Use Number.isNaN to 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.

All Javascript interview questions

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as