How to Test JavaScript Snippets Quickly and Read Console Output

Run small pieces of JavaScript, read console.log, warnings and errors correctly, and choose between a browser console, Node.js and an online runner.

Updated September 29, 2026 6 min read

Use the free JavaScript RunnerRun JavaScript code in your browser and see console.log output

Most JavaScript questions are small. Does Array.prototype.sort sort numbers correctly? What does this date formatting line return in my time zone? Why does this regular expression match twice? You do not need a project for these questions. You need a place to paste ten lines, run them, and read the output.

This guide shows how to test JavaScript snippets efficiently: which console methods to use, how to read error messages and line numbers, how scripts and ES modules differ, and when a browser runner, the built-in developer console or Node.js is the right tool.

What happens when you "run" JavaScript

JavaScript always runs inside a host environment. In a browser, the host provides window, document, fetch and the DOM. In Node.js, the host provides process, require or import of built-in modules, and file system access, but no DOM. The language itself is the same; the available objects differ.

Code can also be loaded in two modes:

Mode How it is loaded Key differences
Classic script <script> Top-level variables become globals; await only inside async functions
ES module <script type="module"> Strict mode always on, top-level await allowed, import statements work

Knowing which mode you are in explains many "works here, fails there" surprises.

Console methods worth knowing

console.log is only the start. A few others make snippets much easier to read:

const orders = [
  { id: 101, region: "North", total: 240 },
  { id: 102, region: "South", total: 185 },
];

console.log("Orders loaded:", orders.length);
console.info("Info messages are useful for milestones");
console.warn("Warnings stand out without stopping the script");
console.error("Errors are highlighted too");

const start = performance.now();
const sum = orders.reduce((acc, o) => acc + o.total, 0);
console.log("Sum:", sum, "in", (performance.now() - start).toFixed(2), "ms");

In a browser's own developer tools you can also use console.table(orders) for a grid view and console.group() to nest related lines. Simpler runners, including ours, print objects as formatted JSON text instead.

Run a snippet with the JavaScript Runner

Our JavaScript Runner executes your code in a sandboxed frame in your browser and shows the console output underneath.

  1. Open the JavaScript Runner. A sample script is loaded that logs an array, calculates a Fibonacci number and prints a warning.
  2. Replace it with your code in the JavaScript box. The code runs automatically shortly after you stop typing.
  3. Read the Console panel. Normal logs are white, console.info is blue, warnings are yellow, and errors are red. Uncaught errors include the line number, for example Uncaught ReferenceError: total is not defined (line 7).
  4. Leave Show run time switched on to see "Finished in … ms" at the end of each run. Turn it off if you want a cleaner console.
  5. Switch on Run as ES module when you need top-level await or want to import a library from a URL. This also turns on strict mode.
  6. Use Re-run to execute the same code again, for example after a random value or timer changes, and Clear in the console header to wipe old output.
  7. Click Download to save the code as script.js.

Anything your script writes to document.body appears in the output frame above the console, which is handy for quick visual checks.

Reading error messages

Most runtime errors fall into a handful of types. Recognising them saves time:

  • ReferenceError: you used a name that does not exist. Check spelling and whether the variable is declared in the current scope.
  • TypeError: you called something that is not a function or read a property of undefined or null. The value is not what you expected; log it just before the failing line.
  • SyntaxError: the code cannot be parsed at all, so nothing runs. Look for a missing bracket, quote or comma near the reported line, and sometimes on the line before it.
  • RangeError: a value is outside what is allowed, such as an invalid array length or runaway recursion.

Unhandled promise rejections are reported separately. In our runner they show as Unhandled promise rejection: followed by the reason. Add a try { … } catch (e) { console.error(e) } around await calls to see the full context.

Other ways to run JavaScript

Your browser's developer console

Press F12 (or Cmd+Option+J in Chrome on Mac) and open the Console tab. It runs code in the context of the current page, which is exactly what you want when debugging that page. It also has richer object inspection than any online runner. It is less convenient for longer snippets, and code typed there is lost when you close the tab.

Node.js

If Node.js is installed, save the code as test.js and run:

node test.js

Node is the right choice for server-side code, file handling or anything using Node-only APIs. It has no document or window, so DOM code fails there.

Unit tests

When a snippet grows into logic you depend on, turn it into a test with a framework your project already uses. A runner is for exploration; tests are for guarantees.

Tips and pitfalls

Floating point surprises

0.1 + 0.2 logs 0.30000000000000004. That is standard IEEE 754 behaviour, not a bug in the runner. Round for display with toFixed() or work in whole units such as cents.

Sorting numbers

[10, 9, 1].sort() returns [1, 10, 9] because the default sort compares strings. Pass a comparator: .sort((a, b) => a - b).

Dates and time zones

new Date("2026-03-01") is parsed as UTC midnight, but toString() shows local time, so it may display the previous day. Log toISOString() when you need an unambiguous value.

Infinite loops

A loop that never ends freezes the frame and can make the tab unresponsive. Add a counter guard while experimenting, and reload the page if it hangs.

Messy input code

If you pasted minified code, format it with the JavaScript Formatter before running, so error line numbers point somewhere meaningful. For inspecting large JSON results, copy the output into the JSON Viewer; for pattern questions, the Regex Tester shows matches more clearly than logging.

Frequently asked questions

Can I use import statements in the runner?

Yes, switch on Run as ES module and import from a full URL, such as a CDN that serves ES modules. Bare package names like import x from "lodash" need a bundler and will not resolve.

Why does console.log show my object as text?

The runner forwards console output from the sandboxed frame as text, converting objects to formatted JSON. Functions, undefined values and circular references cannot be represented in JSON, so they may be simplified or omitted.

Does the runner support top-level await?

Only in module mode. Turn on Run as ES module, or wrap your code in an async function and call it.

Is my code sent to a server?

No. The code runs in a sandboxed frame in your own browser tab. Only network requests your code makes, such as fetch() calls, leave your device.

How accurate is the run time?

It uses performance.now() around the script, so it is good for comparing approaches roughly. For serious benchmarking, repeat the work many times and use your browser's profiler.

Try it now: JavaScript Runner

Loading tool…