Observe before guessing

JavaScript Console Online

Use the HCODX JavaScript console to inspect logs, read errors and debug event handlers while your HTML project runs in preview.

Log valuesRead stack tracesTest events
A diagnostic view

The console shows execution, not just the final picture

The browser preview renders a page; the console reports what your script logs and which operations fail.

When a button appears but does nothing, resist rewriting the whole function. Add one log at the start of the handler. If the log never appears, the event connection is wrong. If it appears, move the log deeper until you find the first unexpected value.

Read the first error before the later ones. A failed selector can make several subsequent lines fail; fixing the earliest cause is usually faster than treating each message as a separate bug.

Syntax errors

The script could not be parsed, so code below the error may never run.

Runtime errors

The script started, then a particular expression failed while executing.

Your logs

A temporary log can show which branch ran and what data it received.

A common failure

A selector typo that stops a click handler

The markup contains #save, but the script asks for #send. The console turns a silent-looking button into a specific diagnosis.

Run the broken snippet and inspect the first error. querySelector returns null for a missing element; calling addEventListener on null then throws. Correct the id in the JavaScript and run the preview again.

If you still see no log after the correction, check when the script runs. A deferred external script or a handler added after DOMContentLoaded avoids querying before the element exists.

The first error is the useful one: it identifies a null target before the click callback can be attached.
<button id="save" type="button">Save draft</button>
<script>
  // Broken: there is no element with id="send".
  const button = document.querySelector("#send");
  button.addEventListener("click", () => {
    console.log("save clicked");
  });
  // Fix by querying "#save" instead.
</script>
Repeatable method

Use a four-step console loop

Make one small hypothesis and collect one piece of evidence at a time.

Reproduce the behavior Use the same click, input or viewport state each time so the result is comparable.
Read the earliest relevant message Locate the file and line, and decide whether the failure happened before or after your handler began.
Log one boundary Print the element, input or branch condition immediately before the failing operation.
Remove temporary logs After the fix, keep meaningful error handling but clear noisy debugging output before export.

If the console points to an external API, check the network request and CORS policy as well; a JavaScript log cannot make a denied cross-origin response readable.

A second diagnosis

The same selector can fail because of load order

A correctly spelled selector still returns null if the script runs before the element exists in the document.

Imagine a script tag in the head that immediately asks for #save. At that point the browser has not parsed the later button, so the query is null even though the button appears after the page finishes loading. The error resembles the typo case, but the fix is different: defer the external script, place an inline script after the element, or wait for DOMContentLoaded.

Check the source location from the console before choosing a fix. If the id matches exactly, inspect when the script executes. After adding defer, refresh and verify that the handler logs only after a click—not during page load.

defer lets the browser parse the button before app.js queries it; the file path must resolve too.
<!-- index.html -->
<head>
  <script src="app.js" defer></script>
</head>
<body>
  <button id="save" type="button">Save draft</button>
</body>

// app.js, parsed after the document when defer is used
const save = document.querySelector("#save");
save.addEventListener("click", () => console.log("save clicked"));
Interpret the signal

A log, a warning and an exception are not the same

The console is useful only if you know whether a line came from your code, the browser or a failed request.

Compare

Your own log

console.log records that a code path ran and can show a value at that point. It does not prove the next line succeeded.

Compare

Thrown exception

An error such as “Cannot read properties of null” usually includes a file and line. Start at the first relevant exception and inspect the expression before it.

Compare

Failed network request

CORS, 404 or blocked-resource messages concern a URL or browser policy. Check the Network panel and origin; rewriting a DOM selector will not repair a rejected response.

Compare

Warning or deprecation

A warning may not stop execution, but it can point to behavior that differs across browsers or will need maintenance. Verify its source before acting.

Console questions

Reading the output correctly

A query did not find the expected element, or code ran before it was available. Check the selector spelling and load order first.

The remote server did not authorize the request’s effective origin to read its response. Check the request and response headers; the API owner may need to change its CORS policy, or your application may need an appropriate backend.

No. It observes JavaScript running in the browser preview. Server logs and backend debugging require the relevant server environment.

The event fired, but a later statement may target the wrong element, set an unchanged value or throw. Add a log after the suspected line and inspect the first exception.

A live preview can rerun the page when source changes. If the underlying bug remains, the same error can appear again in the fresh execution; fix the source rather than only clearing the console.

No. A 404 means a requested resource was not found. Check its URL and relative path first; an exception is a script failure that may be caused by, or separate from, that missing resource.

Debug the first error, not the last symptom

Run a small example, open the console and trace the event one step at a time.

Instant HTML Runner & Viewer with Live Preview

Need to run a short HTML, CSS and JavaScript snippet? The HTML Runner Online has a focused editing surface with live output.

Open HTML Runner Online