Challenge - 5 Problems
Master of Comparison Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediateOutput of chained comparison with mixed types
What is the output of this JavaScript code?
console.log(3 < 4 < 5);
Javascript
console.log(3 < 4 < 5);
Attempts:
2 left
๐ก Hint
Remember that JavaScript evaluates comparisons from left to right and converts booleans to numbers in some cases.
โ Incorrect
The expression 3 < 4 is true, which converts to 1 when compared to 5. Then 1 < 5 is true, so the final output is true. But the code is console.log(3 < 4 < 5), which evaluates as (3 < 4) < 5 โ true < 5 โ 1 < 5 โ true. So the output is true, but the question asks for the output of the code exactly. The code outputs true, so option D is correct.
โ Predict Output
intermediateOutput of strict equality with different types
What is the output of this JavaScript code?
console.log('5' === 5);Javascript
console.log('5' === 5);
Attempts:
2 left
๐ก Hint
Strict equality checks both value and type.
โ Incorrect
The string '5' and the number 5 have different types, so strict equality === returns false.
โ Predict Output
advancedOutput of comparing objects with == and ===
What is the output of this JavaScript code?
const a = {};
const b = {};
console.log(a == b);
console.log(a === b);Javascript
const a = {}; const b = {}; console.log(a == b); console.log(a === b);
Attempts:
2 left
๐ก Hint
Objects are compared by reference, not by content.
โ Incorrect
Both == and === compare object references. Since a and b are different objects, both comparisons return false.
โ Predict Output
advancedOutput of comparing null and undefined with == and ===
What is the output of this JavaScript code?
console.log(null == undefined); console.log(null === undefined);
Javascript
console.log(null == undefined); console.log(null === undefined);
Attempts:
2 left
๐ก Hint
== allows type coercion, === does not.
โ Incorrect
null == undefined is true because == treats them as equal. null === undefined is false because they have different types.
โ Predict Output
expertOutput of comparing NaN with itself
What is the output of this JavaScript code?
console.log(NaN == NaN); console.log(NaN === NaN); console.log(Object.is(NaN, NaN));
Javascript
console.log(NaN == NaN); console.log(NaN === NaN); console.log(Object.is(NaN, NaN));
Attempts:
2 left
๐ก Hint
NaN is not equal to anything, even itself, except with Object.is.
โ Incorrect
NaN == NaN and NaN === NaN both return false. Object.is(NaN, NaN) returns true.
