How to use the online JavaScript compiler
- Write or paste your JavaScript into the editor. You can restore the starter example with Reset example.
- Press Run or use Ctrl + Enter (⌘ + Enter on a Mac).
- Output from
console.log,console.infoandconsole.debugappears in the Output panel.console.warn,console.errorand uncaught exceptions, including their stack traces, are highlighted as errors. - Choose a time limit of 5, 15 or 60 seconds. A script that runs longer is stopped automatically, and you can press Stop whenever you like.
There is nothing to download. JavaScript runs on the engine already built into your browser, so the page is ready immediately. Use Copy or main.js to save your code.
Your code runs locally, in a Web Worker in your own browser. It is never uploaded or stored on our servers. The editor remembers your last code in your browser's local storage, and in no other place.
What's supported
- Modern JavaScript: everything your browser supports, including classes, arrow functions, destructuring, optional chaining (
?.), nullish coalescing (??),BigInt,Map/Setand newer array methods. - Top-level
await: your code is wrapped in an async function, so you canawaitpromises directly. - Timers and promises:
setTimeout,setInterval,Promise.alland similar functions work. The run is considered finished when your top-level code (including any awaited work) completes. - Worker-safe Web APIs such as
JSON,Intl,TextEncoder,crypto.getRandomValuesandstructuredClone.
Limitations:
- No DOM. The code runs in a worker, so
document,windowandalert()are not available. - No
import/require. This is not Node.js, so npm packages and Node modules likefscannot be loaded. console.tableprints its data as JSON rather than as a drawn table.- Behaviour follows the browser you are using. Very new features may be missing in older browsers.
JavaScript quick reference
const scores = { ada: 91, linus: 78, grace: 85 };
const passed = Object.entries(scores)
.filter(([, s]) => s >= 80)
.map(([name, s]) => `${name}: ${s}`);
console.log(passed); // ["ada: 91", "grace: 85"] as JSON
const sleep = ms => new Promise(r => setTimeout(r, ms));
await sleep(100);
console.log(scores.bob ?? 'no score');
| Task | Syntax |
|---|---|
| Declare variables | const x = 1; let y = 2; |
| Arrow function | const add = (a, b) => a + b; |
| Template literal | `Total: ${sum}` |
| Strict equality | a === b |
| Destructuring | const { id, name } = user; |
| Wait for a promise | const data = await promise; |
Tips
- Objects and arrays are printed as indented JSON. Log them directly, for example
console.log({ a, b }), to see variable names next to their values. MapandSetare printed with their size and contents (for exampleMap(2) [...]), andBigIntvalues with annsuffix.- Copy JSON output into the JSON formatter to validate it, or to collapse and explore large structures.
- To tidy messy or minified code, run it through the JavaScript formatter before pasting it here.
- Values attached to
globalThispersist between runs until you press Stop. Variables declared withconstorletdo not.
Frequently asked questions
Which JavaScript version does this run?
Whatever your browser's engine supports: V8 in Chrome and Edge, SpiderMonkey in Firefox, or JavaScriptCore in Safari. Current versions of all of them support modern ECMAScript, including ES2024 features.
Why is document undefined?
To keep the page responsive and safe, your code runs in a Web Worker, which has no access to the page. Use this tool for logic, algorithms and data processing, not for DOM manipulation.
Can I use npm packages?
No. import, require and Node.js built-ins are not available. Only the language and the standard Web APIs that workers provide can be used.
What happens if I write an infinite loop?
The page stays responsive, because the loop runs in a worker. When the time limit is reached, or when you press Stop, the worker is shut down and your code stops.