The Weird Parts __hot__ - Js

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.

const arr = [1, 2, 3]; arr["foo"] = "bar"; console.log(arr); // [1, 2, 3, foo: "bar"] console.log(arr.length); // 3 (still!) The length property only counts numeric indices. The string key "foo" is there, but the array pretends it isn’t. JavaScript tries to be "helpful" with Automatic Semicolon Insertion (ASI). But sometimes, it helps too much. js the weird parts

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. You are not alone

If you’ve spent more than five minutes writing JavaScript, you’ve probably had a moment where you stared at your screen and whispered, “...why?” const arr = [1, 2, 3]; arr["foo"] = "bar"; console