10 JavaScript Mistakes I Made — So You Don’t Have To

By Dhanian Follow me on X: @e_opore | Access my full dev resources: codewithdhanian.gumroad.com I didn’t become a better JavaScript developer by writing perfect code. I became better by making painful, frustrating, tear-inducing mistakes. If you're just getting started or even knee-deep in JS, I want to help you dodge the bullets I took for the team. Here are 10 real JavaScript mistakes I made—so you don’t have to. 1. Confusing == and === I still remember debugging a condition for over an hour: if (userInput == 0) { // ... } It worked... until it didn’t. Turns out "0" == 0 is true but "0" === 0 is false. Lesson: Always use === unless you have a very specific reason. Strict comparison saves lives. 2. Thinking null and undefined Are the Same They’re cousins, not twins. I used to set undefined manually to clear a value. Wrong move. let x = undefined; // Bad let x = null; // Better for intentional "nothing" Lesson: Use null when you mean "empty." Leave undefined to JavaScript. 3. Believing var, let, and const Were Just Spelling Variants I didn’t respect scope. So var betrayed me like a plot twist. function test() { if (true) { var msg = 'hello'; } console.log(msg); // ‘hello’ — wait, what?? } Lesson: Use let for reassignable values and const for constants. Avoid var like unsalted chips. 4. Ignoring NaN and Silent Type Coercion I once tried adding numbers from an input field like this: let total = input1 + input2; Both were strings. So "4" + "4" = "44". Math died inside. Lesson: Always convert types explicitly. let total = Number(input1) + Number(input2); 5. Treating Arrays and Objects the Same I passed an object to a function expecting an array and spent two days debugging. function printNames(names) { names.forEach(...) // TypeError } Lesson: Know your types. Use Array.isArray() when in doubt. 6. Not Understanding this I thought this always referred to the current function. Until I hit this: const person = { name: "Dhanian", greet() { setTimeout(function () { console.log(this.name); }, 1000); } }; undefined logged. I screamed. Lesson: this in regular functions isn't bound. Use arrow functions or .bind() to maintain context. 7. Forgetting async/await Needs try/catch I used await like it was magic. const data = await fetchData(); When fetchData failed, everything crashed silently. Lesson: Use try/catch with await. Async code needs adult supervision. 8. Chaining Promises Without Returning I created a promise chain, but nothing was chaining. doSomething() .then(() => { doAnotherThing(); // Forgot to return }) .then(() => { // This runs too early! }); Lesson: Return inside .then() if you want to chain properly. 9. Using map() When I Meant forEach() I used .map() for side effects. array.map(item => console.log(item)); Then wondered why I had an array of undefined. Lesson: Use .map() to transform. Use .forEach() for side effects. 10. Not Reading Error Messages Fully I used to see red in the console and immediately panic. But JavaScript often tells you what’s wrong. Lesson: Slow down. Read the message. Google the exact error if needed. It's a breadcrumb trail to your fix. Final Thoughts Learning JavaScript isn’t a smooth highway—it’s a trail littered with bugs, facepalms, and lots of console logs. But every mistake made me stronger. Every broken app made me smarter. So if you're feeling overwhelmed—breathe. You’re not alone. I’ve been there. And that’s exactly why I create content—to help you code with fewer tears and more clarity. More Resources Want to learn by building real projects? Check out my ebooks: codewithdhanian.gumroad.com Follow me on X for daily dev wisdom: @e_opore Now You: What’s one mistake you made while learning JavaScript? Drop it in the comments—I’ll read and reply to each!

Apr 18, 2025 - 06:05
 0
10 JavaScript Mistakes I Made — So You Don’t Have To

By Dhanian

Follow me on X: @e_opore | Access my full dev resources: codewithdhanian.gumroad.com

I didn’t become a better JavaScript developer by writing perfect code.

I became better by making painful, frustrating, tear-inducing mistakes.

If you're just getting started or even knee-deep in JS, I want to help you dodge the bullets I took for the team. Here are 10 real JavaScript mistakes I made—so you don’t have to.

1. Confusing == and ===

I still remember debugging a condition for over an hour:

if (userInput == 0) {
  // ...
}

It worked... until it didn’t.

Turns out "0" == 0 is true but "0" === 0 is false.

Lesson: Always use === unless you have a very specific reason. Strict comparison saves lives.

2. Thinking null and undefined Are the Same

They’re cousins, not twins. I used to set undefined manually to clear a value.

Wrong move.

let x = undefined; // Bad
let x = null; // Better for intentional "nothing"

Lesson: Use null when you mean "empty." Leave undefined to JavaScript.

3. Believing var, let, and const Were Just Spelling Variants

I didn’t respect scope. So var betrayed me like a plot twist.

function test() {
  if (true) {
    var msg = 'hello';
  }
  console.log(msg); // ‘hello’ — wait, what??
}

Lesson: Use let for reassignable values and const for constants. Avoid var like unsalted chips.

4. Ignoring NaN and Silent Type Coercion

I once tried adding numbers from an input field like this:

let total = input1 + input2;

Both were strings. So "4" + "4" = "44". Math died inside.

Lesson: Always convert types explicitly.

let total = Number(input1) + Number(input2);

5. Treating Arrays and Objects the Same

I passed an object to a function expecting an array and spent two days debugging.

function printNames(names) {
  names.forEach(...) // TypeError
}

Lesson: Know your types. Use Array.isArray() when in doubt.

6. Not Understanding this

I thought this always referred to the current function. Until I hit this:

const person = {
  name: "Dhanian",
  greet() {
    setTimeout(function () {
      console.log(this.name);
    }, 1000);
  }
};

undefined logged. I screamed.

Lesson: this in regular functions isn't bound. Use arrow functions or .bind() to maintain context.

7. Forgetting async/await Needs try/catch

I used await like it was magic.

const data = await fetchData();

When fetchData failed, everything crashed silently.

Lesson: Use try/catch with await. Async code needs adult supervision.

8. Chaining Promises Without Returning

I created a promise chain, but nothing was chaining.

doSomething()
  .then(() => {
    doAnotherThing(); // Forgot to return
  })
  .then(() => {
    // This runs too early!
  });

Lesson: Return inside .then() if you want to chain properly.

9. Using map() When I Meant forEach()

I used .map() for side effects.

array.map(item => console.log(item));

Then wondered why I had an array of undefined.

Lesson: Use .map() to transform. Use .forEach() for side effects.

10. Not Reading Error Messages Fully

I used to see red in the console and immediately panic.

But JavaScript often tells you what’s wrong.

Lesson: Slow down. Read the message. Google the exact error if needed. It's a breadcrumb trail to your fix.

Final Thoughts

Learning JavaScript isn’t a smooth highway—it’s a trail littered with bugs, facepalms, and lots of console logs.

But every mistake made me stronger. Every broken app made me smarter.

So if you're feeling overwhelmed—breathe. You’re not alone. I’ve been there.

And that’s exactly why I create content—to help you code with fewer tears and more clarity.

More Resources

Now You:

What’s one mistake you made while learning JavaScript? Drop it in the comments—I’ll read and reply to each!