JavaScript Online Compiler
Write JavaScript and run it instantly. Output appears in a built-in console with tables, objects and timings, errors point to the exact line, and runaway loops are stopped automatically. Share your code with a link.
Last updated:
Code runs in an isolated Web Worker on your device: no DOM (document, window), but full modern JavaScript, timers, promises, fetch and top-level await.
How to use the JavaScript Online Compiler
- Write or paste JavaScript in the editor, open a .js file, or pick an example.
- Press Run code or Ctrl + Enter. Output from console.log and friends appears in the console on the right.
- Fix errors by clicking the line link in an error message to jump to that line in the editor.
- Stop long runs with the Stop button; infinite loops are stopped automatically at the time limit.
- Share or save your code with Copy share link or Download.
Console methods you can use
| Method | What it shows | Example |
|---|---|---|
console.log() | Values separated by spaces; objects are formatted and nested up to 4 levels | console.log('total', 42, {a: 1}) |
console.info() / debug() | Like log, marked as info or dimmed | console.info('ready') |
console.warn() / error() | Yellow or red lines, counted in the status bar | console.warn('low stock') |
console.table() | Arrays or objects as a table; optional column list | console.table(users, ['name']) |
console.time() / timeEnd() | Elapsed milliseconds for a labelled block | console.time('sort') |
console.count() | How many times a label was reached | console.count('retry') |
console.group() / groupEnd() | Indents the following lines | console.group('Step 1') |
console.assert() | An error line only when the condition is false | console.assert(x > 0, 'x must be positive') |
console.dir() / trace() | An object, or the current call stack | console.trace('here') |
| Format specifiers | %s string, %d/%i integer, %f float, %o/%O object | console.log('%s is %d', 'Ann', 30) |
How your code runs
When you press Run, the code is first checked for syntax errors. It is then loaded as a classic script into a fresh Web Worker, a background thread with its own global scope. Every run starts clean, so variables from a previous run never leak into the next one. Top-level let, const and function declarations behave like a normal script, and code that uses await at the top level is wrapped in an async function automatically.
The console calls inside the worker are forwarded to the page, together with the line that produced them, and uncaught errors are mapped back to main.js line numbers. The page also sends the worker a heartbeat several times per second. If the code never yields, for example in while (true) {}, the heartbeat goes unanswered and the worker is terminated at the time limit, while the editor stays responsive the whole time.
Tips
- Use Ctrl + Enter (Cmd + Enter on Mac) to run without leaving the keyboard. Tab and Shift + Tab indent and outdent selected lines.
- Click the main.js:line label next to any console line to jump to the code that printed it.
- Compare algorithms with
console.time(), and run them a few times: the first run is often slower because the engine has not optimised the code yet. - Floating-point results such as
0.1 + 0.2 = 0.30000000000000004are normal IEEE 754 behaviour, not a bug in the compiler. UsetoFixed()or integer cents for money.
Frequently asked questions
Is JavaScript compiled or interpreted?
Both, in a sense. Modern engines such as V8 (Chrome, Edge, Node.js), SpiderMonkey (Firefox) and JavaScriptCore (Safari) parse your code, run it in an interpreter and compile frequently used parts to machine code just in time. This tool uses your browser's own engine, so the code runs exactly as it would in a script on a web page.
Why is document or window not defined?
Your code runs in a Web Worker, an isolated thread without access to the page. That keeps the editor responsive and lets infinite loops be stopped safely, but there is no DOM. Plain JavaScript, timers, promises, fetch, JSON, Math, Intl and typed arrays all work. To test code that changes HTML, use the HTML Editor.
What happens if my code has an infinite loop?
The page keeps working because the code runs in a separate thread. When the run exceeds the time limit you chose (5 seconds by default) the worker is stopped and the console explains that the code never paused. You can also press Stop at any time.
Can I use await, promises and timers?
Yes. Top-level await is supported, and the run stays active until all timeouts, intervals, fetch requests and the main async code have finished, up to the time limit. Uncaught promise rejections are reported as errors.
Can I import npm packages or use require?
Not directly. The code runs as a classic script, so import statements and Node.js require are not available. Node-only APIs such as fs and process are also missing. For browser-ready libraries you can use importScripts('https://...') with a full URL.
How do share links work, and is my code private?
The share link stores your code, compressed, after the # in the URL. That part is never sent to a server, so the code stays between you and the people you send the link to. Opening a shared link loads the code but does not run it until you press Run.
How accurate is the execution time?
The time shown is measured with performance.now() around your script, so it includes parsing and running but not page overhead. Timings vary between runs and browsers; use console.time for parts of your code and compare several runs.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.