How to use the JavaScript Online Compiler
- 1. Write your codeType or paste JavaScript into the editor. Tab adds two spaces.
- 2. Press RunYour code runs in a separate worker thread inside your browser.
- 3. Read the consoleSee console.log output, warnings and errors with line numbers.
What runs and what does not
This compiler uses the JavaScript engine already inside your browser, so modern syntax works: let/const, arrow functions, classes, destructuring, spread, async/await, Map, Set and BigInt. setTimeout, setInterval and promises run too, and their output appears as it happens.
Code runs in a Web Worker, a background thread with no page attached. That means document, window and alert are not available. For DOM code, use the online HTML editor instead. Node.js modules such as fs or require do not exist in the browser either.
Example and safety stop
Worked example: the starter code defines a recursive factorial. Running it prints 5! = 120, because 5 × 4 × 3 × 2 × 1 = 120. Next comes the sorted array [1, 2, 3], and after 100 ms timer done appears. The timer line comes last even though it is written before the end of the file, which is the event loop at work.
An accidental while(true) would freeze most online editors. Here the worker is stopped after the time limit you choose (3, 5 or 10 seconds) and the page stays responsive. Output is also capped at 2,000 lines.
- Objects and arrays are printed as formatted JSON.
- Errors show the message and, for syntax errors, the line number.
- Nothing you type is sent to a server.
Frequently asked questions
Can I use import or require?
No. The worker runs a plain script, so ES module imports and Node's require are not available. Paste the functions you need into the editor.
Why do I get 'document is not defined'?
The code runs in a worker thread without a web page. Use the online HTML editor tool to work with the DOM.
Is my code saved?
No, this compiler does not store your code. Copy it somewhere before you leave the page.
Is the compiler free?
Yes, writing code is open to everyone. The first time you press Run we ask for your name and WhatsApp number, and after that all Uncodemy tools run without the form.