0
0
Javascriptprogramming~20 mins

Comparison operators in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Master of Comparison Operators
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2: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);
ATypeError
Bundefined
Cfalse
Dtrue
Attempts:
2 left
πŸ’‘ Hint
Remember that JavaScript evaluates comparisons from left to right and converts booleans to numbers in some cases.
❓ Predict Output
intermediate
2: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);
Atrue
Bfalse
CTypeError
Dundefined
Attempts:
2 left
πŸ’‘ Hint
Strict equality checks both value and type.
❓ Predict Output
advanced
2: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);
Afalse\ntrue
Btrue\ntrue
Cfalse\nfalse
Dtrue\nfalse
Attempts:
2 left
πŸ’‘ Hint
Objects are compared by reference, not by content.
❓ Predict Output
advanced
2: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);
Atrue\nfalse
Bfalse\nfalse
Ctrue\ntrue
Dfalse\ntrue
Attempts:
2 left
πŸ’‘ Hint
== allows type coercion, === does not.
❓ Predict Output
expert
3: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));
Afalse\nfalse\ntrue
Btrue\ntrue\ntrue
Ctrue\nfalse\nfalse
Dfalse\ntrue\nfalse
Attempts:
2 left
πŸ’‘ Hint
NaN is not equal to anything, even itself, except with Object.is.