javascript weird parts
请登录后再继续
帐号:
密码:
安全问题:
您的答案:
 
注册

Javascript Weird | Parts

function show() { console.log(this); } show(); // window (or global in Node) new show(); // {} (the new instance)

if ([]) console.log("truthy"); // Runs! if ({}) console.log("truthy"); // Runs! Empty array and empty object? Truthy. But if ([] == false) ? That’s true (see point #2). Consistency? Not today. JavaScript defines weird type coercion rules for + . javascript weird parts

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. function show() { console

const bound = show.bind({hello: "world"}); bound(); // {hello: "world"} Truthy

Both get converted to strings and concatenated. Not an error. Not useful. Just... weird. JavaScript’s weird parts aren’t bugs—they’re historical artifacts. Brendan Eich built this language in 10 days in 1995. It had to be flexible, forgiving, and fast.