QuizzesEquality & Coercion — == vs === and Why It Matters — Concept Check
intermediate
javascript

Equality & Coercion — == vs === and Why It Matters — Concept Check

Questions on Equality & Coercion — == vs === and Why It Matters. JavaScript will convert types to make a comparison succeed. == does this conversion, === does not, and knowing the handful of rules turns "weird" behaviour into predictable behaviour.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Equality & Coercion — == vs === and Why It Matters — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.In JavaScript, what will be the result of the expression `0 == false`?

    • Atrue, because 0 is truthy
    • Btrue, because both are coerced to numbers before comparison
    • Cfalse, because strict equality is not used
    • Dfalse, because 0 and false are different types
  2. 2.A developer uses `if (value == null)` in their code. What does this condition check for?

    • AIt checks if value is either null or undefined
    • BIt checks if value is truthy
    • CIt checks if value is falsy
    • DIt checks if value is strictly null
  3. 3.Why might `if (!n)` cause a bug when `n` is 0 in JavaScript?

    • ABecause 0 is falsy, causing the block to execute incorrectly
    • BBecause `!n` only checks for undefined
    • CBecause 0 is truthy, preventing the block from executing
    • DBecause `!n` is not a valid condition
  4. 4.What is the result of `1 === '1'` in JavaScript?

    • Afalse, because === does not perform type coercion
    • Btrue, because both values are equal after coercion
    • Ctrue, because both are truthy
    • Dfalse, because 1 is not truthy
  5. 5.A developer uses `const size = input.size || 20;`. Why might this be problematic if `input.size` is 0?

    • A0 is truthy, so it defaults to 20, which may not be intended
    • B0 is falsy, so it defaults to 20, which may not be intended
    • C`||` only works with strings
    • D`||` does not handle null values correctly
  6. 6.What happens when `null == undefined` in JavaScript?

    • Afalse, because strict equality is not used
    • Bfalse, because they are different types
    • Ctrue, because they are special-cased to be equal
    • Dtrue, because both are falsy
  7. 7.In JavaScript, what does the expression `[] == ![]` evaluate to and why?

    • Afalse, because `[]` and `![]` are different types
    • Bfalse, because `[]` is truthy and `![]` is falsy
    • Ctrue, because both are coerced to the same type
    • Dtrue, because `[]` is coerced to false
  8. 8.Why might a developer prefer `??` over `||` for default values in JavaScript?

    • A`??` only falls back on null or undefined, avoiding truthiness issues
    • B`??` is faster than `||`
    • C`||` only works with numbers
    • D`||` is deprecated in modern JavaScript