🟑 MediumType CoercionπŸ’» Output Question

Comparison coercion

πŸ’‘

Hint

String comparison is lexicographic (char by char). null equality is special β€” it only equals undefined.

What does this output?

console.log('10' > '9');
console.log('10' > 9);
console.log(null > 0);
console.log(null == 0);
console.log(null >= 0);

Correct Output

false
true
false
false
true

Why this output?

Explanation: "10">"9": string comparison β€” "1" vs "9" by char code, "1"<"9" so false. "10">9: string vs number, "10"β†’10, 10>9=true. null: null==0 is false (special rule). null>=0 is true (numeric: 0>=0). null>0 is false (numeric: 0>0).

Key Insight: String comparison is lexicographic (char by char). null equality is special β€” it only equals undefined.

More Type Coercion Output Questions

🟒 EasyLoose equality coercionβ†’πŸŸ‘ MediumAddition vs concatenationβ†’πŸŸ‘ MediumFalsy values comparisonβ†’πŸŸ‘ MediumNaN comparisonβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz