ZL
About Articles Contact
Published on Nov 17, 2017
Filed under:
#javascript,
#video

How to debug Javascript errors

It’s normal for you to make errors when you code. So if you see an error, you don’t have to be afraid. I get error messages all the time. When I have bad days, I get more error messages!

Error messages are something bad. We’re actually lucky to have error messages show up infront of us when code.

Think about designers and other professions, when they create something, its hard for them to know what’s wrong with their work.

In our case, we get instant feedback through error messages. These error messages are like angels that gently tell us that something is wrong. You can correct the code and your program would work.

Let’s go through an example.

In this code, we’re trying to add an event listener to a button, and when the button is clicked, the button should turn orange.

If you hit the refresh button, you’ll see an error message. The first thing you do is to breathe and relax.

Then, you read the error message. You also look at where the message occurs.

The error message says you can’t read a property addEventListener of null. If you’re unsure whether btn is null, you can do a console.log.

Here, you’ll understand you missed a . when declaring the btn variable. What you’ll need to do is fix this querySelector declaration and your code works.

I hope this video has been helpful for you.

If you like this video, you might want to consider subscribing to this youtube channel, and I’ll send you a helpful tip about frontend development every friday.

You may also want to consider subscribing over at my blog at zellwk.com, and you’ll get one article plus one video from me every week to help you become a better frontend developer.

Now good luck, and have a nice day!

Previous Case study—a project from hell Next How to build a calculator—part 1

Join My Newsletter

I share what I’m learning on this newsletter: code, building businesses, and living well.

Sometimes I write about technical deep-dives, product updates, musings on how I live, and sometimes my struggles and how I’m breaking through.

Regardless of the type of content, I do my best to send you at least one insightful piece every week.

If you’re into making things and growing as a person, you’ll probably feel at home here.

“

Zell’s writing is very accessible to newcomers because he shares his learning experience. He covers current topics and helps all readers level up their web development skills. Must subscribe.

Chen Hui Jing
Chen Hui Jing — Web Developer
The Footer

General

Home About Contact Testimonials Tools I Use

Projects

Magical Dev School Splendid Labz

Socials

Youtube Instagram Tiktok Github Bluesky X

Follow Along

Email RSS
© 2013 - 2026 Zell Liew / All rights reserved / Terms