Run / log / debug

JavaScript Console Online

Write or paste JavaScript, select Run and see everything it logs: values, objects, tables, warnings and errors with the line they came from. Your code runs in an isolated worker in your browser, so it is never uploaded and an endless loop cannot freeze the page.

console.log, table, warn and errorLine numbers on errorsStops runaway code after 10 seconds
Try it here

Run your JavaScript

Write code on the left, then select Run or press Ctrl+Enter. Output appears on the right in the order it was logged, and Stop ends a run at any time.

This console runs plain JavaScript in a Web Worker, so there is no web page here: document and window are not defined. Variables, functions, classes, promises, async/await, timers and fetch all work. To change HTML elements, use the HTML Runner, which has a console under its preview.

HCODX / console output
    JavaScript console

    What a JavaScript console is for

    A console is the quickest way to answer a small question about your code: what does this return, and why does it fail?

    Many JavaScript questions are too small for a project. Does sort() order numbers the way you expect? What does this regular expression match? What is the date thirty days from now? Paste a few lines here, log the result and you have an answer in seconds. Try [10, 9, 1].sort() and you will see [1, 10, 9], because sort compares items as text unless you pass a compare function.

    Output is formatted so structure is easy to read. A string you log directly is printed as it is, while strings inside objects keep their quotes. Objects appear as { key: value }, arrays as lists, Maps and Sets with their size, and an object that refers to itself is shown as [Circular] instead of crashing. console.table turns an array of objects into an aligned table, and console.group indents the messages that follow.

    Each run starts a fresh Web Worker inside a sandboxed frame. The worker is a separate thread, so a loop that never ends cannot lock up the page; select Stop, or the run ends by itself after ten seconds. The sandbox also gives the code an anonymous origin, which keeps it away from anything this site stores in your browser, such as projects saved in the HCODX editor.

    Tables and objects

    console.table, nested objects, Maps, Sets and dates are printed in a readable form.

    Errors with line numbers

    Each error shows its type and message; select the line link to highlight the code.

    Isolated and private

    Code runs in your browser, in a worker that cannot freeze the page or read site data.

    Beyond console.log

    Console methods worth knowing

    console.log covers most needs, but a few other methods make output much easier to read.

    Paste this into the console above and run it. console.table is the fastest way to inspect a list of records. console.count and console.time answer "how many times" and "how long" without extra variables, and console.assert only prints when a condition is false, which keeps output quiet while everything is correct.

    Warnings and errors are colored differently from ordinary logs, so they stand out in long output. In a browser's DevTools the same methods also let you filter messages by level.

    Useful console methods
    const users = [
      { name: "Ada", role: "admin", active: true },
      { name: "Lin", role: "editor", active: false },
    ];
    console.table(users);
    
    console.group("Checks");
    console.assert(users.length === 3, "Expected 3 users, got", users.length);
    console.warn("Lin is inactive");
    console.groupEnd();
    
    for (const user of users) console.count(user.role);
    
    console.time("loop");
    let sum = 0;
    for (let i = 0; i < 1e6; i++) sum += i;
    console.timeEnd("loop");
    Debugging

    How to read a JavaScript error

    Every error message has the same three parts. Read them in order and most bugs explain themselves.

    01

    Read the type

    ReferenceError means a name does not exist, usually a typo or a variable used before it is declared. TypeError means a value is the wrong kind, often undefined. SyntaxError means the code could not be parsed at all.

    02

    Read the message

    "Cannot read properties of undefined (reading 'apply')" says something.apply was used where something was undefined. The property name in brackets tells you which access failed.

    03

    Go to the line

    Select the line link next to the error to highlight it. Log the values used on that line to find which one is not what you expected.

    04

    Fix the first error

    An early failure can cause later ones. Fix the first error in the list, run again, and only then look at the next.

    A SyntaxError stops the whole run before anything is logged, so if you see no output at all, look for a missing bracket or quote near the reported line.

    Choose the right tool

    This console, the HTML Runner or browser DevTools?

    All three show console output; they differ in what your code can reach.

    Plain JavaScript

    This console

    Logic, data and API calls with no page involved. Fast to start, isolated, and nothing to set up.

    Code and a page

    HTML Runner

    JavaScript that reads or changes HTML elements, with a live preview and a console under it.

    A live site

    Browser DevTools

    Debugging a page that is already running, with breakpoints, the network panel and the DOM inspector.

    Questions

    JavaScript console questions

    No. It runs in a worker inside your own browser tab. Nothing is uploaded or saved, and the code is gone when you close the page.

    The console runs in a Web Worker, which has no web page, so document and window do not exist. Use the HTML Runner for code that works with HTML elements.

    Yes. Your code runs inside an async function, so await works at the top level. fetch works with APIs that allow cross-origin requests. Requests come from an anonymous origin, so APIs that rely on your cookies will treat you as signed out.

    The page stays responsive because the code runs on a separate thread. Select Stop to end it; otherwise the run is stopped after ten seconds with a message suggesting where to look.

    No. Every run starts in a fresh worker, so results are reproducible and an earlier experiment cannot affect the next one.

    No, there is no package manager. To experiment with a library, load it with a script tag in the HTML Runner or use an online environment that installs npm packages.

    The same ones your browser supports, because the code runs in your browser's own JavaScript engine. Current versions of Chrome, Edge, Firefox and Safari support modern syntax such as optional chaining, classes and async iteration.

    Need a page to go with your script?

    Open the HTML Runner to combine HTML, CSS and JavaScript with a live preview and a console under it.

    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