Javascript Weird | Parts
const bound = show.bind({hello: "world"}); bound(); // {hello: "world"}
console.log(NaN === NaN); // false Yes, NaN is not equal to itself. You must use Number.isNaN() instead. This is the gateway drug of JS weirdness.
JavaScript is the most misunderstood language in the world. Some call it broken; others call it beautiful. The truth? It’s both. javascript weird parts
Let’s pop the hood and explore the —the quirks that make you scratch your head, and ultimately, make you a better developer. 1. typeof NaN === "number" (Excuse me?) You try to parse an integer from a string like "hello" . You get NaN (Not-a-Number). You ask JavaScript what type it is:
If you’ve spent more than 48 hours with JavaScript, you’ve probably uttered the phrase: “Wait… why did it do that?” const bound = show
console.log(0.1 + 0.2); // 0.30000000000000004 console.log(0.1 + 0.2 === 0.3); // false Floating-point math. JavaScript uses binary floating point; 0.1 in binary is a repeating fraction (like 1/3 in decimal). It can't be represented exactly.
Arrow functions don't have their own this —they inherit from the parent scope. That’s often a lifesaver, but it’s another thing to memorize. Every value in JS is inherently truthy or falsy. There are exactly 8 falsy values : JavaScript is the most misunderstood language in the world
const obj = { show }; obj.show(); // obj