Weird Parts — Js The

console.log([] + []); // "" (empty string) console.log([] + {}); // "[object Object]" console.log({} + []); // 0 (wait, WHAT?) The last one is a parsing quirk. In some engines, {} at the start of a line is treated as an empty block, not an object. So {} + [] becomes + [] which coerces to 0. Never, ever trust == . It’s like asking a toddler if two things are the same.

console.log(typeof NaN); // "number" Yes. The representation of "Not a Number" is technically a number. And as we saw, it refuses to be friends with anyone, including itself. The only reliable way to check for NaN is: js the weird parts

function showThis() { console.log(this); } showThis(); // window (or undefined in strict mode) console

You are not alone. JavaScript is the quirky, misunderstood genius of the programming world. It was built in 10 days, it drives the modern web, and it has a list of "features" that look more like bugs. Never, ever trust ==

Scroll to Top