JavaScript Playground

Type JavaScript and press Run, or Ctrl+Enter. Everything passed to console.log shows in the Console, with objects, arrays, Maps and errors printed the way a browser console prints them.

How it works

Your code runs as an ES module inside a sandboxed frame that you do not see. A module runs in strict mode and allows await at the top level, so you can await a promise without wrapping your code in an async function.

The frame has an anonymous origin and a Content Security Policy that blocks fetch, XMLHttpRequest, WebSocket and scripts loaded from a URL. Your code can compute, use timers and build DOM elements, but the usual ways of reaching the network are switched off.

console.log, info, warn, error and debug are passed back to this page and printed in the Console. Uncaught errors and rejected promises are printed too, with the line of your code they came from where the browser reports one.

How to use it

  1. 1 Type or paste JavaScript into the box.
  2. 2 Press Run, or Ctrl+Enter (Cmd+Enter on a Mac).
  3. 3 Read the output in the Console. Errors are highlighted and name their line.
  4. 4 Edit the code and run it again. Each run starts in a fresh sandbox with a clean Console.

Good to know

  • Each run is a new, empty page. Variables from the last run are gone, so a run never depends on what you ran before.
  • console.clear() empties the Console from inside your code.
  • import from a URL and fetch are blocked here. Paste any helper code you need straight into the box.
  • An endless loop can freeze this tab. If it does, close the tab and open the tool again.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Why 1, 4, 3, 2: the event loop in four lines

A playground is the right place to test a claim about JavaScript instead of trusting it. Here is one that surprises most people. Type these four lines and press Run: console.log(1); setTimeout(() => console.log(2), 0); Promise.resolve().then(() => console.log(3)); console.log(4);. The Console prints 1, 4, 3, 2. The timer has a delay of zero and still comes last.

The order comes from how JavaScript schedules work. The script itself runs first, top to bottom, with nothing able to interrupt it. So 1 is printed, the timer is registered, the promise callback is queued, and 4 is printed. Only when the script has finished does the engine look at the waiting work.

There are two queues. Promise callbacks go into the microtask queue, and the engine empties it completely as soon as the current script ends. So 3 comes next. Timer callbacks are tasks, and a task runs only after the microtasks are done and the browser has had its chance to do other work. A delay of 0 means "as soon as possible after that", not "now". So 2 comes last.

Now change the code to check your model. Add await null; console.log(5); at the end. Because this playground runs your code as a module, top-level await is allowed. await null waits for one turn of the microtask queue, so the output becomes 1, 4, 3, 5, 2. The 5 comes before the timer and after the promise callback that was queued before it, which is exactly what the two-queue picture predicts. If your guess was wrong, the Console shows it at once, and that is the point of trying it.

The same method works for any question about the language: how sort compares numbers (try [10, 9, 1].sort()), what 0.1 + 0.2 really gives, or whether a Map keeps insertion order. Write the smallest code that answers the question, guess the output, then run it.

This playground has limits. It blocks network requests, so fetch, WebSocket and import from a URL are blocked, and there are no npm packages. It runs plain JavaScript only, not TypeScript or JSX. The Console prints values as text, so you cannot expand an object to look inside it, and very deep objects are cut short. An endless loop can freeze the tab, and nothing you type is saved.

Frequently asked questions

Does this support top-level await and modern syntax?

Yes. The code runs as a module, so await works at the top level, and every syntax your browser supports works here: optional chaining, classes with private fields, and so on. It is your browser’s own JavaScript engine, so a very new feature works only if your browser has it.

Can I use npm packages or import from a CDN?

No. There is no package manager, and the sandbox blocks loading scripts from any URL, including module imports. The Console shows a "Blocked by the sandbox" line if your code tries.

Can I use fetch to test an API?

Not here. fetch is blocked, so code you paste cannot quietly send requests from this page. To try an API, use the HTTP Client tool on YappyKit, which sends requests on purpose.

Is my code sent to a server to run?

No. It runs in your own browser, in a frame on this page. Nothing is uploaded and nothing is saved, so copy your code before you close the page.

What happens if my code never stops?

An endless loop keeps the processor busy, and because the sandbox may share this page’s thread, the whole tab can freeze. Close the tab and reopen the tool. Code that waits forever on a promise is harmless: it simply never prints.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.