Web Programming, Linux System Administation, and Entrepreneurship in Athens Georgia

Js The Weird Parts ((link)) 【LIMITED – 2024】

const bound = showThis.bind("hello"); bound(); // String {"hello"}

So next time you see [] + [] returning "" , don’t cry. Laugh. Then fix it. And remember: you’re not alone. What’s the weirdest JavaScript bug you’ve ever encountered? Hit reply or drop a comment—I’d love to compare war stories.

And arrow functions? They don’t have their own this at all—they inherit from the surrounding scope. Arrays in JS are just objects with numeric keys and a special length property. That means you can do... questionable things. js the weird parts

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.

function oops() { accidentalGlobal = "I'm everywhere now"; } oops(); console.log(window.accidentalGlobal); // "I'm everywhere now" You didn't use var , let , or const ? Congratulations, you just polluted the global object. This is why we have linters and "use strict" . The this keyword is like a chameleon on caffeine. Its value depends entirely on how a function is called. const bound = showThis

const obj = { showThis: showThis }; obj.showThis(); // obj

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. And remember: you’re not alone

console.log(isNaN(NaN)); // true // But wait... console.log(isNaN("hello")); // true (because "hello" can't be a number) That’s why ES6 gave us Number.isNaN() which actually behaves. In many languages, if you forget to declare a variable, you get an error. In JavaScript (non-strict mode), you get a present :

© 2025 Brandon Checketts

Theme by Anders NorenUp ↑