JavaScript Type Coercion & Comparison Evaluation

📊 Day 9 – Poll Answer & Explanation console.log(1 < 2 < 3); console.log(3 > 2 > 1); 🧠 Concept: Type Coercion & Comparison Evaluation in JavaScript In JavaScript, comparisons are evaluated **from left to right**. When a **boolean** is used in another comparison, JavaScript converts it to a **number**. true → 1 false → 0 🔍 Step-by-step explanation ✅ First Expression 1 < 2 < 3 Step 1 1 < 2 ✔️ true Step 2 true < 3 true → 1 1 < 3 ✔️ true Output: true ⚠️ Second Expression 3 > 2 > 1 Step 1 3 > 2 ✔️ true Step 2 true > 1 true → 1 1 > 1 ❌ false Output: false 🖨️ Final Output true false 🎯 Key Takeaway JavaScript **does not support chained comparisons like math**. 3 > 2 > 1 is evaluated as: (3 > 2) > 1 true > 1 1 > 1 false 💡 Tip: Use logical AND for correct comparison. console.log(3 > 2 && 2 > 1); // true #JavaScript #JSConcepts #TypeCoercion #TrickyQuestions #Frontend #PollAnswer

To view or add a comment, sign in

Explore content categories