Developed By Ken Key

JavaScript in 2026: The Stuff That Actually Trips People Up

By Ken Key Dec 16, 2024 4 min read Updated Oct 16, 2026

JavaScript in 2026: The Stuff That Actually Trips People Up
The short answer

The bugs that trip people up most are closures in loops, what this points to, and the difference between var and let. Fix the loop with let, remember this depends on how a function is called, not where it's written.

Part of the complete web development guide.

On this page

Most JavaScript bugs I get called about aren’t exotic. They’re the same handful of language quirks that have confused people for a decade, just wearing new clothes in 2026. Here’s a plain explanation of each one, why it bites you, and how to write code that avoids the trap in the first place.

Closures are not magic, they’re just scope

A closure is a function that remembers the variables from where it was defined, even after that outer function has returned. That’s the whole idea. The confusion comes from loops.

// Broken: every button logs 3
for (var i = 0; i < 3; i++) {
 document.getElementById('btn' + i).addEventListener('click', () => {
 console.log(i);
 });
}

// Fixed: let creates a new binding per iteration
for (let i = 0; i < 3; i++) {
 document.getElementById('btn' + i).addEventListener('click', () => {
 console.log(i);
 });
}

With var, there’s one i shared by all three handlers, and by the time you click, the loop has finished and i is 3. With let, each iteration gets its own binding. This is the single most common closure question I see, and it’s been the answer since ES6. If you’re still writing var in a loop that creates functions, stop.

this depends on how you call the function

People expect this to point at the object where the method is defined. It doesn’t. It points at whatever is to the left of the dot when you call it, or undefined in strict mode, or the global object in sloppy mode.

const timer = {
 seconds: 0,
 start() {
 setInterval(function () {
 this.seconds++; // this is NOT timer here
 console.log(this.seconds); // NaN
 }, 1000);
 }
};

// Fix 1: arrow function inherits this from start()
const timer2 = {
 seconds: 0,
 start() {
 setInterval(() => {
 this.seconds++;
 console.log(this.seconds); // works
 }, 1000);
 }
};

Arrow functions don’t have their own this. They inherit it from the surrounding scope. That makes them the right tool for callbacks and the wrong tool for object methods you plan to call with a dot. I covered a version of this in a piece on custom web development a while back, and it’s still the number one thing that breaks when someone refactors a class into an object literal.

Async ordering: promises don’t run when you think

JavaScript is single-threaded, but it has a microtask queue and a macrotask queue. Promises go in the microtask queue, which runs before the next macrotask. That means the order of your logs is not the order you wrote them.

console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
console.log('4');

// Output: 1, 4, 3, 2

If you’ve ever wondered why a .then() fired before a setTimeout with zero delay, that’s why. This matters in real code when you’re mixing timers, fetch calls, and DOM updates and expecting a specific sequence. When order matters, chain your work in one async function with await instead of scattering callbacks.

== versus === and the coercion rules

Loose equality coerces types before comparing. Strict equality doesn’t. The coercion table is long and full of surprises.

  • 0 == '' is true
  • '0' == false is true
  • null == undefined is true, but null === undefined is false
  • NaN === NaN is false, use Number.isNaN()

The rule is simple: always use === unless you have a specific reason not to. The one place I still use == is checking for null or undefined in one shot, because x == null catches both and nothing else.

Floating point math is not broken, it’s binary

0.1 + 0.2 === 0.3 // false
0.1 + 0.2 // 0.30000000000000004

Computers store decimals in binary, and some decimal fractions can’t be represented exactly. This isn’t a JavaScript bug. It’s the same in Python, Java, and every language using IEEE 754 doubles. For money, work in cents as integers or use a decimal library. For display, round to the precision you actually need.

Mutating arrays while looping over them

If you splice an array while iterating forward, you skip elements. The index keeps advancing while the array shrinks underneath you.

const nums = [1, 2, 3, 4, 5];

// Broken: skips 2 and 4
for (let i = 0; i < nums.length; i++) {
 if (nums[i] % 2 === 0) nums.splice(i, 1);
}

// Fixed: build a new array
const odds = nums.filter(n => n % 2 !== 0);

Prefer filter, map, and reduce over in-place mutation. They’re easier to read and they don’t have this class of bug. Reach for splice only when you actually need to mutate in place, and iterate backward if you do.

Why any of this matters

Every one of these quirks has a straightforward fix. The trick is recognizing the pattern before it ships. If you’re maintaining a JavaScript codebase and these keep showing up in your bug tracker, the problem usually isn’t the language. It’s that the code was written by copy-paste instead of by someone who understood the scope rules. I’ve been doing this since the jQuery era, and the fundamentals haven’t changed. Only the syntax around them has.

FAQ

Should I use var at all in 2026?

No. Use const by default and let when you need to reassign. var has function scoping and hoisting behavior that causes bugs, and there’s no modern reason to reach for it.

Do arrow functions replace regular functions everywhere?

No. Use arrow functions for callbacks where you want this from the enclosing scope. Use regular functions for object methods, constructors, and anywhere you need your own this or the arguments object.

Is floating point math ever going to be fixed?

No, and it doesn’t need to be. It’s how floating point works across every language. For money, use integers (cents) or a decimal library. For everything else, round when you display.

Have a project like this?

I do custom web development for Long Island businesses. If you need this done right, let’s talk.