Challenge - 5 Problems
Master of Comparison Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β Predict Output
intermediate2:00remaining
Output 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
intermediate2:00remaining
Output 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
advanced2:00remaining
Output 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
advanced2:00remaining
Output 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
expert3:00remaining
Output 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.