How to use the JS console simulator
- Type or paste code into the JavaScript box. A sample is there to start with.
- Press Run, or Ctrl+Enter. While a run is still going, the button reads Re-run and starts over.
- Read the output below. Each console call is one row: warnings are marked ▲ and errors ✖, and grouped rows are indented.
- The status line shows Finished in N ms, or why the run stopped. Press Stop to end a long run and Clear to empty the output.
What it does and when to use it
Use it to check what an expression returns, test an array method or a regex replace, or follow a tutorial example. It is quicker than opening developer tools, and the code cannot touch the page you are on.
It is not a full runtime. There is no DOM, no network and no npm packages, and the run is stopped after 5 seconds. To check syntax without running anything, use the JavaScript validator. To delete logs before you ship, use the console.log remover. To make a snippet readable first, run it through the JavaScript formatter.
How it works
When you press Run, the page creates a hidden frame with the sandbox="allow-scripts" setting and no same-origin permission, so the frame has an opaque origin. Inside it, a Web Worker runs your code with a replacement console object. Each call turns its arguments into a safe description of the values and posts it back to the page, which prints them the way browser consoles do: strings unquoted at the top level and quoted inside objects.
Besides log, info, warn, error and debug, it supports table, assert, count, time, group and clear, plus format strings such as %s and %d.
Worked examples
These rows come from the simulator’s own value printer.
Arrays and objects.
const users = [{ name: 'Asha', age: 31 }, { name: 'Ben', age: 27 }];
console.log('Users:', users.length);
console.table(users);
console.warn('Done');
prints Users: 2, then [ { name: 'Asha', age: 31 }, { name: 'Ben', age: 27 } ], then a warning row Done.
Format strings, counters and groups. console.log('%s scored %d%%', 'Asha', 92.7) prints Asha scored 92%, because %d keeps the whole number. Two console.count() calls print default: 1 and default: 2. Inside console.group('Totals'), console.log(new Map([['a', 1]]), new Set([1, 2])) prints an indented Map(1) { 'a' => 1 } Set(2) { 1, 2 }.
An error and a timer.
setTimeout(() => console.log('later'), 0);
console.log('now');
null.x;
shows now, then a red Uncaught TypeError row. later never appears, because the run had already finished.
Limits and tips
- Output limits. Only the last 500 rows are kept. Arrays, maps and sets show their first 100 items, strings are cut at 10,000 characters, and objects nested more than 5 levels deep show
[Object]. - Top-level await is a syntax error, since the code runs as a script, not a module.
Frequently asked questions
Is it safe to run code I found online?
Why don't my setTimeout or promise logs appear?
Can I use document, window or alert?
What happens with an infinite loop?
Does console.table draw a table?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.