Skip to content
Online Compiler

Online JavaScript Compiler

Write JavaScript and run it right here. It runs in your browser, so nothing you type is uploaded.

Ready

// Runs in your browser. prompt() reads one line from the input box.
const name = prompt() ?? "world";
console.log(`Hello, ${name}!`);

for (let i = 1; i <= 3; i++) {
  console.log(i, "squared is", i * i);
}

Type the input before you run. Each prompt() call reads the next line.

Output

Press Run or Ctrl+Enter to see the output here.

Runs in your browser with Browser JavaScript (Web Worker). Your code is not sent to a server.

How to run JavaScript code here

  1. Write or paste your JavaScript code into the editor. There is a short example in it to start from.
  2. If your program reads input, type it into the input box first — one value per line.
  3. Press Run or Ctrl+Enter. The output appears next to the editor, with errors shown in red.

How this page runs JavaScript

Runtime: Browser JavaScript (Web Worker)

Your code runs in your browser's own JavaScript engine, inside a Web Worker that is kept apart from the page. Modern syntax works as written: let and const, arrow functions, classes with private fields, optional chaining, and await at the top level. console.log, console.info and console.debug go to the output; console.error and console.warn are shown as errors. Timers such as setTimeout keep the program alive until they have fired.

Everything happens on your device. The code you write is never uploaded, logged or stored on a server. Each run stops after 10 seconds and keeps up to 100,000 characters of output, so an endless loop cannot freeze the page.

What is not available

This is browser JavaScript, not Node.js. require, npm packages, fs, process and the other Node APIs are not available, and because the code runs in a worker there is no document or window to draw on. Every run starts in a fresh worker, so variables and timers from the previous run are gone.

JavaScript examples

Open an example in the editor above, change it and run it. Opening an example does not run it.

FizzBuzz with a for loop

for (let i = 1; i <= 15; i++) {
  const word = (i % 3 === 0 ? "Fizz" : "") + (i % 5 === 0 ? "Buzz" : "");
  console.log(word || i);
}

Arrays: filter, reduce and sort

const scores = [72, 95, 58, 88, 64];

const passed = scores.filter((s) => s >= 60);
const average = scores.reduce((sum, s) => sum + s, 0) / scores.length;

console.log("passed:", passed);
console.log("average:", average.toFixed(1));
console.log("sorted:", [...scores].sort((a, b) => b - a));

A class with a private field

class Account {
  #balance = 0;
  constructor(owner) {
    this.owner = owner;
  }
  deposit(amount) {
    this.#balance += amount;
    return this;
  }
  get balance() {
    return this.#balance;
  }
}

const account = new Account("Ada").deposit(50).deposit(25);
console.log(account.owner, account.balance);
console.log(JSON.stringify({ owner: account.owner, balance: account.balance }));

Promises and top-level await

const wait = (ms, value) => new Promise((resolve) => setTimeout(() => resolve(value), ms));

console.log("start");
const results = await Promise.all([wait(300, "slow"), wait(100, "fast")]);
console.log(results);
console.log("done");

Adding up numbers from the input

// Each prompt() call reads the next line of the input box.
const count = Number(prompt());
let total = 0;
for (let i = 0; i < count; i++) {
  total += Number(prompt());
}
console.log("sum:", total);

Input

3
10
20
30

Reading input in JavaScript

Programs here do not stop and wait for you to type while they run. Everything your program reads comes from the input box, which you fill in before pressing Run.

Call prompt() to read the next line of the input box as a string, and convert it with Number() when you need a number. Once every line has been read, prompt() returns null, so a loop like while ((line = prompt()) !== null) reads all of the input.

Saving and sharing

Your latest JavaScript code and input are saved automatically in this browser, so they are still here when you come back. Nothing is saved on a server.

Share creates a link that carries your code inside the address itself, compressed after the # sign. Whoever opens it sees your code in the editor, and it only runs when they press Run.

Keyboard shortcuts

KeysAction
Ctrl+EnterRun the code
Ctrl+/Comment or uncomment the line
Tab · Shift+TabIndent or outdent the selection
Ctrl+FFind and replace in the code
Ctrl+Z · Ctrl+Shift+ZUndo / redo
Esc → TabLeave the editor with the keyboard

On a Mac, use ⌘ instead of Ctrl.

Frequently asked questions

Can I use Node.js features such as require or fs?

No. The code runs in the browser's JavaScript engine, not in Node.js, so require, npm packages, the file system and process are not there. Everything in the language itself works, along with the built-ins that need no page, such as timers, Math, Date, JSON, Map, Set and Intl.

Can my code change the page or use the DOM?

No. Your program runs in a Web Worker, which has no document or window. That separation is deliberate: code you open from a shared link cannot touch the page, your saved code or anything else in the browser. Use console output to show results.

Which JavaScript version is supported?

Whatever your browser supports. Current versions of Chrome, Edge, Firefox and Safari handle modern JavaScript, including classes with private fields, optional chaining, top-level await and the newer array methods.

Is this JavaScript compiler free?

Yes. There is no account, no sign-up and no daily limit. The only limit is that a single run stops after 10 seconds.

Is my JavaScript code sent to a server?

No. The JavaScript runtime is downloaded into your browser and your code runs there, on your device. The site only serves the page and the runtime files; it never receives the code you write or the input you give it.

Where is my code saved?

In this browser's local storage, one draft per language. It stays until you clear this site's data, and it is not synced to other devices. Use a share link to move code somewhere else.

How do I share my JavaScript code?

Press Share and send the copied link. The code is compressed into the part of the link after #, which browsers never send to a server. Very long programs do not fit in a link, and the page will tell you when that happens.

Does it work on a phone or tablet?

Yes. It runs in any current mobile browser. On a slow connection the first run takes longer because the runtime has to be downloaded once.

Run another language