Challenge 1 +20 XP
Use the strict equality operator to check if a is equal to b.
- Test 1 — expects "true"
Need a hint? (−25% XP)
Use === between a and b.
Show solution (0 XP)
const a = 10;
const b = 10;
const res = a === b;
console.log(res); JavaScript uses booleans (true and false) to make decisions. You generate these by comparing values.
JavaScript has two ways to check if values are equal. The strict equality operator === compares both the value and the type.
console.log(5 === 5);true
If you compare two different types using strict equality, it evaluates to false:
console.log(5 === '5');false
However, JavaScript also has a loose equality operator == that attempts to coerce types to match before comparing them. Let’s see what happens if we use == instead.
Read the code. What exactly will it print? Commit to an answer before you look.
console.log(5 == '5');true
Trap: Because
==coerces types,1 == true,'0' == false, and[] == 0all evaluate totrue! You should almost always use===to prevent massive bugs in your applications.
The loose equality operator (==) exists because JavaScript attempts to convert and compare operands that are of different types. That sounds convenient — 1 == '1' being true saves a conversion. The trouble is that the coercion rules are not a single simple rule but a table of them, and the surprising entries surface as bugs long after the comparison was written.
Use === unless you have a specific reason not to. It skips conversion altogether: different types are simply not equal. Objects are the exception to both. == and === compare objects by identity, not contents, so {} === {} is false — two separate objects that happen to look alike. Comparing their contents is something you have to do yourself.
You can combine multiple boolean conditions together using Logical operators.
AND (&&): Returns true only if BOTH sides are true. Let’s step through this evaluation visually:
console.log(true && false);false
OR (||): Returns true if AT LEAST ONE side is true.
console.log(true || false);true
NOT (!): Inverts the boolean.
console.log(!true);false
Warning: There is one value in JavaScript that breaks all equality rules.
NaN === NaNevaluates tofalse! It is the only value in the language that is not strictly equal to itself.
Which operator should you use to check if two values are exactly identical in both value and type?
=== — The strict equality operator (===) checks both type and value.
What is the result of true && false?
false — Logical AND (&&) requires both conditions to be true.
Is NaN === NaN true or false?
false — NaN is the ONLY value in JavaScript that is not strictly equal to itself!
Use the strict equality operator to check if a is equal to b.
Use === between a and b.
const a = 10;
const b = 10;
const res = a === b;
console.log(res); Use the logical AND operator so that res evaluates to true.
Use && between condition1 and condition2.
const condition1 = true;
const condition2 = true;
const res = condition1 && condition2;
console.log(res);