Online JavaScript compiler

Write JavaScript, press Run and see the console output right next to your code. Errors, warnings and async logs show up as they happen.

Runs in your browser. Nothing you enter is uploaded.

Ctrl + Enter runs the code. Code runs in a sandboxed worker: no DOM, stopped after 5 seconds.

Console

How to use the online JavaScript compiler

  1. Type or paste your code into the JavaScript box, or click Example to load a sample.
  2. Click Run, or press Ctrl + Enter, to execute it.
  3. Read the results in the Console panel: errors appear in red and warnings in orange.
  4. Edit and run again as often as you like; your code is kept in your browser for next time.

Is JavaScript compiled or interpreted?

Both, behind the scenes. Browser engines such as V8 in Chrome and Edge, SpiderMonkey in Firefox and JavaScriptCore in Safari parse your code, start running it right away, and compile the parts that run often into fast machine code while the program is running. This is called just-in-time compilation.

So unlike C or Java, there is no separate compile step that you run by hand. An online JavaScript compiler simply runs your code and shows the result. Tools that do transform JavaScript ahead of time, like the TypeScript compiler, Babel or a bundler, produce JavaScript as their output, which then runs the same way.

What code can I run here?

Any standard JavaScript your browser supports: variables, functions, classes, array methods, JSON, Math, Date, Map and Set, promises, async functions and setTimeout. The code runs in a Web Worker, a background thread with no web page attached, so document and window do not exist. Code that changes HTML fails with ReferenceError: document is not defined; use an HTML editor with a live preview for that.

await only works inside an async function here, so wrap top-level awaits in one, for example (async () => { … })(). Each run starts fresh, and anything still running after 5 seconds is stopped, which protects the page from infinite loops.

How does the console show values?

Strings print as plain text and numbers as numbers. Objects and arrays print as compact JSON, so { user: 'ada', admin: true } appears as {"user":"ada","admin":true}. Dates print in ISO format, errors as their type and message such as TypeError: x is not a function, and an object that refers to itself shows [Circular] instead of crashing the output.

Frequently asked questions

Why do I get "document is not defined"?

Your code runs in a Web Worker, which has no web page and therefore no document or window. This keeps the tool safe and lets it stop runaway code. Plain JavaScript logic works fine; to try code that builds or changes HTML, use an HTML editor with a live preview instead.

What happens if my code has an infinite loop?

The runner stops it. Every run gets 5 seconds; if the code is still busy after that, the worker is shut down and the console shows Execution timed out after 5 s. The page itself never freezes, so you can fix the loop and run again.

Can I use async/await, promises and setTimeout?

Yes. Promises, timers and async functions all work. Output from them can appear after the "Finished in" line, because that line marks the end of the synchronous part of your script. Callbacks are allowed to run until the 5-second limit.

Which JavaScript version does it support?

Whatever your browser supports, because your browser's own engine runs the code. Current versions of Chrome, Edge, Firefox and Safari handle modern syntax such as optional chaining (a?.b), nullish coalescing (??), classes with private fields and Array.prototype.at.

Is my code uploaded or saved?

Your code never leaves your device: it runs locally in your browser. The editor saves your latest code in your browser's local storage so it is still there when you return. Clearing your browser's site data removes it.

Related tools