Finding a JavaScript error and fixing JavaScript code with browser debugging tools.

JavaScript Fixer: Find the Cause Before Changing Code

Open your browser’s developer console and reproduce the failure before editing. A tool that fixes JavaScript can suggest changes, but an error message and a repeatable example give you evidence to evaluate them. A JavaScript error-finding workflow starts with the observed result, then traces it back to the value or operation that caused it.

JavaScript error finder: reproduce the failure

Save this complete page as example.html, open it in a browser, open developer tools, and click Show name:

<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Debug example</title></head>
<body>
  <button id="show">Show name</button>
  <p id="output"></p>
  <script>
    const user = { name: "Ava" };
    function showName() {
      const label = user.namme.toUpperCase();
      document.querySelector("#output").textContent = label;
    }
    document.querySelector("#show").addEventListener("click", showName);
  </script>
</body>
</html>

The expected result is AVA in the paragraph. Instead, the console reports a TypeError because user.namme is undefined, and undefined has no toUpperCase() method. Browser wording can differ. Click the file-and-line link beside the error to inspect the failing expression. The stack trace also shows the function and call path that reached it.

Separate three kinds of failure

A JavaScript error finder can surface a message, but the category determines the next step:

  • Syntax error: code cannot be parsed, for example a missing closing brace. The reported location is a starting point; the mistake may be earlier.
  • Runtime error: valid syntax reaches an invalid operation. The misspelled property in the example produces a runtime TypeError when the button is clicked.
  • Logic error: code runs but produces the wrong result. Using toLowerCase() here would display ava without throwing, contrary to the expected AVA.

Finding errors in JavaScript also means comparing actual behavior with a specific expected result. Record the input, the action, and the output so another developer can reproduce the same failure. A linter can flag some suspicious patterns, while a JavaScript fixer may propose a replacement. Neither can reliably infer every intended result. In particular, an unknown object property is not automatically a syntax error. Test the behavior you actually need.

Inspect the value, then fix JavaScript

In Chrome DevTools, open Sources, select the page, and click the line number containing const label to set a breakpoint. Click the button again. Execution pauses before that line. Inspect user in the Scope panel or evaluate user.namme in the console; it is undefined. The existing property is name. The call stack shows how execution reached showName.

Change user.namme to user.name in the saved file. This fixes the JavaScript property access rather than hiding the exception. If the data can legitimately lack a name, define and test that case separately instead of assuming the property always exists. Remove the breakpoint when you finish, then reload the page so the browser uses the saved change.

Verify the correction

Open the console, reload, and click Show name again. The paragraph should display AVA and the click should produce no TypeError. Repeat the click to confirm that the result stays the same. As a negative check on your expected behavior, temporarily change the name to "Mia", reload, and confirm that the page shows MIA; restore the sample afterward. A clean console alone is not enough: the displayed value is the observable test of the intended logic.

Sources: MDN: Troubleshooting JavaScript; Chrome DevTools: Pause with breakpoints. Accessed November 20, 2026.