Online JavaScript Compiler: write and run JavaScript in your browser

JavaScript

main.js

Output

Output appears here when you press Run.

Input

What is JavaScript?

JavaScript is the programming language of the web. Every browser runs it, it powers the interactive part of nearly every website, and through Node.js it runs servers, command-line tools and build systems too. It is one of the most widely used languages in the world and a common first language for anyone learning to code.

Why use an online JavaScript compiler?

  • Nothing to install. No Node.js, no project, no terminal. Open the page and start writing.
  • Output you can read. Arrays, objects, Maps and class instances print as text, the way they appear in tutorials and in Node, not as a tree you have to click open.
  • Practise as you learn. Run the examples from a course or tutorial as you read them, change them, and see what breaks.

Example

main.js
const scores = { Asha: 88, Rohan: 72, Meera: 95 };

Object.entries(scores)
  .sort(([, a], [, b]) => b - a)
  .forEach(([name, score]) => {
    const grade = score >= 85 ? "A" : "B";
    console.log(`${name.padEnd(6)} ${score}  ${grade}`);
  });
Output
Meera  95  A
Asha   88  A
Rohan  72  B

About Gradient Learning's JavaScript Compiler

It runs your code on your browser's own JavaScript engine, the same one that runs every website you visit, so it supports modern JavaScript and your code never leaves your computer. Errors come back with the line and column in main.js and a pointer to the exact spot, the way Node.js reports them.

What can you do with it?

  • Write and run modern JavaScript, free, with no sign-up
  • Use console.log, console.table, console.error and the other console methods
  • Use async/await, promises and timers, including top-level await
  • Feed your program input for prompt() calls
  • Open a .js file, and download your code as main.js
  • Stop a program that runs too long, with one click

How to use the tool

  1. Write or paste your code into the main.js panel on the left.
  2. If your program uses prompt(), type one line for each call in the Input box on the right.
  3. Press Run, or Ctrl+Enter (⌘+Enter on a Mac). Output and any errors appear in the Output panel.

Frequently asked questions

Is my code uploaded anywhere?

No. Your code runs on your own browser's JavaScript engine, inside your browser, and is never sent to a server, stored or logged. There is nothing to download either: the browser already is the runtime.

Which version of JavaScript does it support?

Whatever your browser supports, which in a current Chrome, Edge, Firefox or Safari is modern JavaScript: classes, arrow functions, destructuring, optional chaining, async/await, top-level await and the latest array methods. An older browser may reject the newest syntax.

Is this Node.js?

No. It is the same language, but not Node's built-in modules: require, import, fs, path and process are not available. console, timers, promises, fetch and the whole standard library (Math, JSON, Date, Map, Set, Intl and so on) are. Output is formatted the way Node prints it, so it matches what tutorials show.

How do I give my program input?

Type the values in the Input box before you press Run, one line for each prompt() call. prompt() returns the next line as a string, and the line it read is shown in green in the output. If your program asks for more lines than you gave it, prompt() returns null, just as it does when somebody cancels a prompt dialog.

Can I use document, window or the DOM?

No. Your code runs in a background worker so that a slow or endless program cannot freeze the page, and a worker has no page to change. Anything that needs document or window, such as adding elements or listening for clicks, will report that they are not defined.

When does my program finish?

When it has nothing left to do, the same rule Node.js uses: after the last line has run and every setTimeout, setInterval and fetch it started has completed. A setInterval that is never cleared keeps the program running until you press Stop.

My program never finishes. What do I do?

Press Stop. It shuts the program down immediately, including an endless loop, and the next Run starts from a clean slate.

Is this a compiler or an interpreter?

Both, in a sense. Browsers compile JavaScript to machine code just in time as it runs, but there is no separate compile step for you to run. Online JavaScript compiler is simply the name most people search for.