What runs, and how
Your code runs in a Web Worker inside a sandboxed frame, with the latest JavaScript syntax, top-level await and strict mode, as in a module (assigning to an undeclared variable is an error). import and export aren't available: the code runs on its own, without network access.
Every run starts fresh: a new Worker with nothing left over from the previous run. A run finishes when your code has returned and no timers are left. If it is still going when the time limit is reached (5 seconds by default), it is stopped, so an accidental while (true) never freezes the page.
How to use the JavaScript Playground
- Write or paste JavaScript in the editor, or load an example.
- Press Run, or Ctrl+Enter (⌘+Enter on a Mac).
- Read the output in the console: click an object or array to expand it.
- Press Stop to end a run early, or raise the time limit for slow code.
- Press Copy share link to share the code: it goes in the link itself.
Examples
Microtasks run before timers
console.log("1: script start");
setTimeout(() => console.log("5: setTimeout"), 0);
Promise.resolve().then(() => console.log("3: promise"));
queueMicrotask(() => console.log("4: queueMicrotask"));
console.log("2: script end");1: script start
2: script end
3: promise
4: queueMicrotask
5: setTimeoutPromise callbacks and queueMicrotask run as soon as the script ends; setTimeout waits for the next task.
Maps, Sets and circular objects
const tags = new Set(["js", "ts", "js"]);
const scores = new Map([["ada", 98], ["linus", 87]]);
console.log(tags, scores);
const node = { id: 1, children: [] };
node.parent = node;
console.log(node);
console.log([1, 2, 3].map(String), 2n ** 64n, -0, 0.1 + 0.2);Set(2) {'js', 'ts'} Map(2) {'ada' => 98, 'linus' => 87}
{id: 1, children: [], parent: [Circular]}
['1', '2', '3'] 18446744073709551616n -0 0.30000000000000004The Set drops the duplicate, the circular reference is marked instead of crashing, and BigInt, -0 and floating-point results are shown exactly.
A console that shows real values
console.log here doesn't turn values into JSON. Objects and arrays show a one-line preview and expand on click; Maps show key => value; Sets, typed arrays, dates, regular expressions, functions, classes, BigInts, -0 and NaN all appear as themselves; and an object that refers to itself shows [Circular] instead of failing.
console.info, warn, error, assert, count, time/timeEnd, group/groupEnd, table and clear work, and %s, %d, %i, %f and %c substitutions are applied. Uncaught errors and unhandled promise rejections are shown with their stack, pointing at lines in your code.
Why it's safe to run code from anywhere
Code is treated as untrusted. The sandbox frame has a unique, opaque origin, so the code can't read this page, your cookies or your saved tools; it can't navigate the page, open windows or show dialogs; and a strict Content Security Policy blocks every network request. The page accepts only well-formed messages from the sandbox, and stopping a run discards the sandbox completely.
The event loop, in four lines
Synchronous code runs first, then every queued microtask (promise callbacks and queueMicrotask), and only then the next task, such as a setTimeout callback, even one with a delay of 0. Load the event loop example and run it to see the order.
Options
- Time limit
- How long a run may last: 5, 10 or 30 seconds. A run that is still busy, or still has timers pending, is stopped when it is reached.
- Examples
- Load ready-made code: array methods, the event loop, async/await, data structures, errors and an infinite loop.
Limitations
- No network access:
fetch,XMLHttpRequestandWebSocketare blocked by the sandbox, andimport/exportaren't available. - No DOM: the code runs in a Web Worker, so
documentandwindowdon't exist. Use the console to see results. evalandnew Functionare blocked by the sandbox's Content Security Policy.- Output stops after 1,000 lines or 1 MB per run; the code keeps running until it finishes or reaches the time limit.
- Code is kept only in this browser (local storage), so you can come back to it on this device.
Frequently asked questions
Is my code sent to a server?
No. It runs in your browser, in a sandbox, and is saved only in this browser's local storage so it's still there next time. Nothing you type is uploaded or sent to analytics.
Can I use top-level await?
Yes. You can await a promise at the top level, as in a JavaScript module, without wrapping your code in an async function.
Why does my infinite loop stop after a few seconds?
Each run has a time limit (5 seconds by default, up to 30). When it is reached the sandbox is discarded and a new one is created, so the page stays responsive. Press Stop to end a run sooner.
Why is `document` undefined?
The code runs in a Web Worker, which has no page to change. That keeps the sandbox fast to stop and safe. Worker APIs such as setTimeout, structuredClone, crypto.randomUUID and TextEncoder are available.
How do I share code?
Press Copy share link. The code is compressed into the link itself, after the #, which browsers never send to a server, so nothing is uploaded or stored. Opening the link loads the code into the editor, replacing the code saved in that browser. Very long code makes long links, which some chat apps cut off.
Can I use TypeScript?
Use the TypeScript Playground: it removes the types and runs the result here, with the same console.