Debugging JavaScript

Knowledge Videos

Short animated explainers, organised by subject.

Debugging JavaScript

Find bugs in JavaScript: console.log to look, reading an error message and its line, and a breakpoint to pause and step through code in DevTools.

Transcript

Bugs happen in JavaScript too. The first tool is console dot log. Print a value, and you can see what it really is.

When something breaks, read the error message. It tells you what went wrong, and on which line. Start there.

A breakpoint pauses your program on a line. In DevTools, open the Sources tab, click a line number, and reload. The program stops, and you can see the value of every variable.

Now step through the code one line at a time, and watch the values change. Predict what the value should be. When it is different, you have found the bug.

Remember: use console dot log to look, read the error message and its line, and use a breakpoint to pause and step. Predict, run, compare, fix.

More in this series