Utilrix

Online JavaScript Compiler

Write and run JavaScript instantly in your browser — real console output, stdin, and no server round-trip.

1:1
OUTPUT

Press Run — output appears here. Everything executes in this tab, so nothing is uploaded and there is no queue to wait in.

Runs in a sandboxed worker in this tab — no server, and a runaway loop is stopped after 8s instead of hanging.

JavaScript examples you can run

Every one of these is loaded from the Examples menu in the editor above — press Run and it works. They are printed here so you can read the code before you run it.

Array methods

map, filter and the object shorthand — the operations most day-to-day JavaScript is made of.

const users = [
  { name: "Vivek", role: "admin" },
  { name: "Rahul", role: "editor" },
  { name: "Amit", role: "viewer" },
];

const names = users.map((user) => user.name);
console.log(names);

const admins = users.filter((user) => user.role === "admin");
console.log("Admins:", admins);

async / await

Top-level await, Promise.all for parallel work, and console.time to measure the difference against a sequential loop.

// Top-level await works here — no wrapper function needed.
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

async function fetchUser(id) {
  await wait(150);
  return { id, name: "User " + id };
}

console.log("Fetching three users in parallel...");
const users = await Promise.all([1, 2, 3].map(fetchUser));
console.table(users);

console.time("sequential");
for (const id of [4, 5]) {
  const user = await fetchUser(id);
  console.log("Got", user.name);
}
console.timeEnd("sequential");

Classes & inheritance

Class inheritance with super, private #fields, a getter, and sorting objects by a computed value.

class Shape {
  constructor(name) {
    this.name = name;
  }
  area() {
    return 0;
  }
  toString() {
    return this.name + " with area " + this.area().toFixed(2);
  }
}

class Circle extends Shape {
  #radius;

  constructor(radius) {
    super("Circle");
    this.#radius = radius;
  }
  area() {
    return Math.PI * this.#radius ** 2;
  }
}

class Rectangle extends Shape {
  constructor(width, height) {
    super("Rectangle");
    this.width = width;
    this.height = height;
  }
  area() {
    return this.width * this.height;
  }
}

const shapes = [new Circle(3), new Rectangle(4, 5)];
for (const shape of shapes) {
  console.log(String(shape));
}

shapes.sort((a, b) => b.area() - a.area());
console.log("Largest:", shapes[0].name);

Reading input (stdin)

Reading standard input with readline() and prompt() — the pattern coding-judge problems use.

// Values come from the Input panel — one per line.
const name = readline();
const age = Number(readline());

console.log("Hello, " + name + "!");

if (Number.isNaN(age)) {
  console.error("That age wasn't a number.");
} else {
  console.log("Next year you turn " + (age + 1) + ".");
}

const city = prompt("Which city?");
console.log("City:", city ?? "(nothing left to read)");

Closures & memoisation

A counter that keeps private state, and memoisation with a Map, which is why fib(90) returns instantly.

function counter(start = 0) {
  let count = start;
  return {
    increment: () => ++count,
    decrement: () => --count,
    get value() {
      return count;
    },
  };
}

const clicks = counter();
clicks.increment();
clicks.increment();
clicks.decrement();
console.log("Clicks:", clicks.value);

function memoize(fn) {
  const cache = new Map();
  return (n) => {
    if (cache.has(n)) return cache.get(n);
    const result = fn(n);
    cache.set(n, result);
    return result;
  };
}

const fib = memoize((n) => (n < 2 ? n : fib(n - 1) + fib(n - 2)));
console.log("fib(90) =", fib(90));

Map, Set & console.table

Grouping with Map, de-duplicating with Set, and printing a real table with console.table.

const orders = [
  { id: "A-1", city: "Jaipur", total: 2400 },
  { id: "A-2", city: "Pune", total: 990 },
  { id: "A-3", city: "Jaipur", total: 1500 },
];

console.table(orders);

const byCity = new Map();
for (const order of orders) {
  byCity.set(order.city, (byCity.get(order.city) ?? 0) + order.total);
}
console.log(byCity);

console.log("Unique cities:", new Set(orders.map((order) => order.city)));

const sorted = [...byCity.entries()].sort((a, b) => b[1] - a[1]);
console.log("Top city:", sorted[0][0], "->", sorted[0][1]);

Errors & debugging

throw and catch with a custom error type, plus what an uncaught exception reports.

function parseAge(input) {
  const age = Number(input);
  if (Number.isNaN(age)) {
    throw new TypeError(input + " is not a number");
  }
  return age;
}

for (const value of ["31", "abc"]) {
  try {
    console.log("Parsed:", parseAge(value));
  } catch (error) {
    console.error("Failed on", value, "->", error.message);
  }
}

console.warn("This is a warning.");
console.log({ nested: { deep: { value: [1, 2, { ok: true }] } } });

// An uncaught throw reports its line — click the line number to jump there.
null.forEach(() => {});

JavaScript quick reference

The syntax people look up most often. Copy any line into the editor above to see what it does.

Array methods you will reach for most

WhatSyntaxNotes
maparr.map(fn)New array, one result per element.
filterarr.filter(fn)Keeps elements where fn is truthy.
reducearr.reduce(fn, initial)Folds the array to one value.
findarr.find(fn)First match, or undefined.
some / everyarr.some(fn)Boolean: any / all match.
flatMaparr.flatMap(fn)map then flatten one level.
sortarr.sort((a, b) => a - b)Sorts in place; always pass a comparator for numbers.
atarr.at(-1)Negative indexes count from the end.

Async patterns

WhatSyntaxNotes
awaitconst data = await promiseWorks at the top level here — no wrapper function needed.
Parallelawait Promise.all([a, b])Runs together; rejects if any one does.
Settle allawait Promise.allSettled(list)Waits for every result, success or failure.
Delaynew Promise((r) => setTimeout(r, ms))The idiomatic sleep.
Timeoutawait Promise.race([work, timeout])First to settle wins.

Modern syntax worth knowing

WhatSyntaxNotes
Optional chaininguser?.address?.cityundefined instead of a TypeError.
Nullish coalescingvalue ?? fallbackOnly falls back on null or undefined, unlike ||.
Destructuringconst { a, b = 1 } = objPull fields out, with defaults.
Spread{ ...obj, extra: 1 }Shallow copy plus overrides.
Logical assignmentobj.list ??= []Assign only if null or undefined.
Structured clonestructuredClone(obj)Deep copy without JSON round-tripping.

Other languages you can run here

Processed 100% in your browser — nothing you enter here is ever uploaded.

Common use cases

Testing a snippet without opening an IDE

Check what .reduce() does to your array, or whether that regex matches, without creating a project or leaving the browser.

Learning JavaScript

Load an example — array methods, async/await, classes, closures — read it, change it, and see what happens immediately.

Interview and DSA practice

Reads stdin the way judge sites do, so you can practise problems that take input, then share a link to your solution.

Working offline or on locked-down Wi-Fi

Once the page has loaded, running JavaScript needs no network at all — useful on a flight, a train, or a network that blocks compiler sites.

How to use the JS Compiler

Write or paste JavaScript in the editor and press Run — or just hit Ctrl + Enter. The first run starts instantly because there is no server to send your code to.

Output appears in the console on the right, formatted the way Node prints it: arrays as [ 1, 2, 3 ], objects with their keys, Maps and Sets with their sizes.

If something throws, the error shows the line number. Click it and the cursor jumps straight to that line.

Need input? Open the Input panel and type one value per line — readline(), prompt() and input() read them in order.

Turn on suggestions in the Editor panel to get method completions as you type, or press Ctrl + Space to ask for them. Ctrl + / comments a block, Ctrl + D duplicates a line, Alt + ↑/↓ moves one.

Press ZIP to download a runnable project, or Share to copy a link with your code encoded inside it.

Frequently asked questions

Related tools