LESSON 10 OF 10
Debugging and a Mini Project
Read errors and combine variables, functions, and events.
Before this lesson: complete the preceding lessons or review their examples. No installation or account is needed.
The idea
Debugging starts with an observation: what did you expect, and what happened instead? Read the first relevant console error, inspect its line, and check the values entering that code. SyntaxError points to invalid syntax; ReferenceError often signals a missing name; TypeError can mean an operation does not fit a value.
At a glance
| Syntax | Purpose |
|---|---|
console.log(value) | Inspect a value at a point in execution |
breakpoint | Pause in Developer Tools to inspect state |
try / catch | Handle exceptions when recovery is possible |
Try it yourself
Build a click counter. The preview supplies a button with id greet and a paragraph with id message. Rename the button, then count its clicks.
Ready. Run the example to open its preview.
Console output
Not run yet.
Page preview
Expected result
No console output. The preview starts at Steps completed: 0.
What to watch for
Change one thing at a time and rerun. If a button does nothing, check the selector and console before rewriting the logic. An infinite loop can freeze its execution context; avoid infinite loops when editing examples. This guide ends at browser fundamentals; asynchronous code and modules are next steps.
Your turn
Add a reset button that sets the count back to zero and calls render(). Try clicks, reset, then another click.
Show one solution
const reset = document.createElement("button");
reset.textContent = "Reset";
document.body.append(reset);
reset.addEventListener("click", () => {
count = 0;
render();
});Check your understanding
What should you check when a selector-based update throws a TypeError?
Check whether the selector returned null, and confirm that the target element exists before the code runs.
Read alongside this lesson
W3Schools: Debugging and a Mini Project · All learning sources