JavaScript Quirks That Will Make You Say “Wait, What?”
Strange-looking JavaScript behaviors explained with simple examples and the rules behind them.

Question - 1
console.log(null === undefined) //false
Why it's false.👀
Expression*:*
null === undefinedResult*:*
false
Explanation
In JavaScript, both null and undefined represent "empty" values but are distinct (different) types.
null is a special object representing the intentional absence of a value, while undefined signifies that a variable has been declared but not assigned a value.
Despite their similar purpose, they are not strictly equal (===) to each other.
null === undefinedevaluates tofalsebecause JavaScript does not perform type coercion with===.
Question - 2
console.log(5 > 3 > 2) //false
Why it's false.👀
Expression*:*
5 > 3 > 2Result*:*
false
Explanation
At first glance, this expression may appear to be checking if 5 is greater than 3 and 3 is greater than 2, but JavaScript evaluates it left-to-right due to its operator precedence.
First,
5 > 3evaluates totrue.Then,
true > 2is evaluated, which in JavaScript results in1 > 2(sincetrueis coerced to1), which evaluates tofalse.
So, 5 > 3 > 2 evaluates to false.
Question - 3
console.log([] === []) //false
Why it's false.👀
Expression*:*
[] === []Result*:*
false
Explanation
In JavaScript, arrays are objects. Even if two arrays have the same content, they are still different objects in memory.
When you compare two
arrayswith===, you are comparing theirreferences, not theircontents.Since
[]and[]are different instances in memory, so the result isfalse.
Question - 4
console.log("10" < "9"); //true
Why it's true.👀
Expression*:*
"10" < "9"Result*:*
true
Explanation
When JavaScript compares strings, it compares their Unicode values lexicographically (character by character).
"10"is compared to"9". Since"1"has a lower Unicode value than"9", JavaScript determines that"10"is less than"9".This comparison might seem
counterintuitive, but it's due to JavaScript'sstringcomparison mechanism.
Question - 5
console.log(NaN === NaN);
Why it's false.👀
Expression*:*
NaN === NaNResult*:*
false
Explanation
In JavaScript, NaN (Not-a-Number)is a special value that represents an invalid number or the result of an operation that cannot produce a valid number.
One of the most unusual aspects of
NaNis that it is not equal toitself. This behavior exists due to the design of theIEEE 754 standard, which JavaScript follows forfloating-point arithmetic.As a result,
NaN === NaNreturnsfalse.
To check if a value is