Javascript Weird Parts _top_ «TRUSTED · 2025»

const arr = [1, 2, 3]; const obj = { a: 1 }; console.log(arr + arr); // "1,2,31,2,3" (string) console.log(arr + obj); // "1,2,3[object Object]"

console.log(1 + "2"); // "12" (string) console.log(1 + 2 + "3"); // "33" (evaluates left to right: 3 + "3") console.log([] + []); // "" (empty string) console.log([] + {}); // "[object Object]" console.log({} + []); // 0 (Wait, run this in a console... yes, 0) The last one is a parsing edge case where {} is interpreted as an empty code block, not an object. This one angers accountants and mathematicians equally. javascript weird parts

const bound = show.bind({hello: "world"}); bound(); // {hello: "world"} const arr = [1, 2, 3]; const obj = { a: 1 }; console

Use a small epsilon or multiply by powers of 10 for money calculations (or use BigInt for integers). 5. Automatic Semicolon Insertion (ASI) JavaScript tries to be helpful. Sometimes too helpful. const bound = show