Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.6 — Equality and Truthiness
JavaScript · Example 3 of 4

Objects are equal only to themselves

c is not a copy: it's a second name for the object a points to.

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.

01

Log whether the string "10" and the number 10 are strictly equal, then convert the string so that the strict comparison is true.

02

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.

03

Log the result of Boolean for these values and explain any surprise: "0", [], NaN, " ".

Explain it without notes

01

What is the difference between == and ===? Which do you use and why?

02

Why is [] == false true, while [] is truthy?

03

What does Object.is do differently from ===?

04

List the falsy values in JavaScript. What's a common bug caused by truthiness checks?

Objects are equal only to themselves

Console

(nothing was printed)

Expected console output

false true
false
true
99