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 Setting up Visual Studio Code (Part 3)—Extensions Next Responsive Vertical Rhythm with CSS Custom Properties and CSS Calc

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 to live, and sometimes my struggles and how I’m breaking through.

Regardless of the type of content, I do my best to send you an update every week.

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

“

Zell is the rare sort of developer who both knows his stuff and can explain even the most technical jargon in approachable — and even fun — ways!

I’ve taken his courses and always look forward to his writing because I know I’ll walk away with something that makes me a better front-ender.

Geoff Graham
Geoff Graham — Chief Editor @ CSS Tricks
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 - 2025 Zell Liew / All rights reserved / Terms