Check out a free preview of the full JavaScript: From First Steps to Professional course

The "Debugging" Lesson is part of the full, JavaScript: From First Steps to Professional course featured in this preview video. Here's what you'd learn in this lesson:

Anjana discusses methods to go about debugging and how to provide more information on bugs and errors using console.log, .warn(), .error(), and the console's debugger.

Preview
Close

Transcript from the "Debugging" Lesson

[00:00:00]
>> Okay, so another thing that we're gonna run into in the real world are bugs in our code. I hate to break it to you, but no matter how good you get at JavaScript, you're never gonna be a perfect software developer because that thing does not exist. And so we all have bugs in our code from time to time, or you could say, like share in clueless we are like totally bugging.

[00:00:24]
Question is what do we do about it? So how can we be bugging? Yeah, so that's what we're gonna talk about now. Again, because the fact of life a certainty of life especially in a loosey goosey kind of language like JavaScript where you could get undefined anytime or it doesn't really care if you pass in the wrong arguments to a function, stuff is gonna go wrong.

[00:00:50]
Spectacular failure is part of the game of being a JavaScript developer. So we just have to be able to roll with the punches and try to figure out when we have something wrong in our code try to figure out what is going wrong. So for example, one of the things that we could do that I definitely use plenty and we could use to kind of check our understanding of what's happening in our code is to log things to the console.

[00:01:21]
So this can be a useful way for us to kind of assure ourselves of, let's say the fact that we're executing the body of a function if we log something when we start running that function body then we know that we got that far. And then we also have our console.warn and console.error if we want to kind of make it pop out a little bit more with those exclamation point, warning signs in the browser.

[00:01:47]
And so we can do things like let's say log values, logs certain things within our code just to make sure to kind to check our understanding and to make sure that things are giving us the values that we expect. Sort of how in the console like as we've been working iteratively on our different functionality, we've been just checking things like, is an empty array truthy or falsey?

[00:02:12]
Or did we get the right poodle standard string that we wanted out of this particular function? That sort of thing. So console log is a totally valid debugging technique that you can use, but sometimes you don't want your program really cluttered up with all kinds of console log statements.

[00:02:29]
So often this will be a temporary thing that as a developer you're working through, you're developing locally, you're testing things out, you're maybe logging some things. You probably wanna remember to take them out at the end. And so sometimes that can mean that things get forgotten, things get left in there, you end up with a whole bunch of console output.

[00:02:45]
And sometimes if you're loading a web page out there, and now that we're all using our developer tools and inspecting the page and looking at the console you might see stuff that's logging out from somebody else's code because they were just checking values and things like that. So that is one thing we can do to be debugging.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now