JavaScript Type Coercion – The Silent Bug Factory

Ever encountered weird behavior in JavaScript like this? console.log(1 + "1"); // "11" (String) console.log(1 - "1"); // 0 (Number) console.log([] + []); // "" (Empty String) console.log([] + {}); // "[object Object]" console.log({} + []); // 0

Feb 26, 2025 - 06:12
 0
JavaScript Type Coercion – The Silent Bug Factory

Ever encountered weird behavior in JavaScript like this?

console.log(1 + "1");  // "11"  (String)
console.log(1 - "1");  // 0  (Number)
console.log([] + []);  // ""  (Empty String)
console.log([] + {});  // "[object Object]"
console.log({} + []);  // 0