NaN, -0 and Object.is
Use === to compare values without hidden conversion, Object.is for the two cases === gets wrong (NaN and -0), and learn the eight falsy values, because every if converts its condition to true or false.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Log whether the string "10" and the number 10 are strictly equal, then convert the string so that the strict comparison is true.
Write a check that logs missing when a variable discount is null or undefined, but not when it is 0. Test it with all three values.
Log the result of Boolean for these values and explain any surprise: "0", [], NaN, " ".
Explain it without notes
What is the difference between == and ===? Which do you use and why?
Why is [] == false true, while [] is truthy?
What does Object.is do differently from ===?
List the falsy values in JavaScript. What's a common bug caused by truthiness checks?
Console
(nothing was printed)Expected console output
false true
true false
true false
true -1