Text & Developer tool

Online JavaScript Compiler and Console

Write JavaScript, press Run and read the console output.

  • Instant results
  • Working shown
  • No sign-up
  • Runs in your browser
ToolUpdates as you type
Examples:
Console output
Press Run to see console.log output and errors here.

Your code runs only in your browser, inside a locked-down frame with no access to this site. Nothing is uploaded or saved. Press Ctrl + Enter to run and Tab to indent. An endless loop will freeze the tab; close and reopen it if that happens.

How it works

This online JavaScript compiler runs your code when you press Run or Ctrl + Enter. Everything you print with console.log, console.warn or console.error appears in the console panel, and errors show the line number from your editor. Your code runs in a sandboxed frame inside your own browser.

This online JavaScript compiler is a quick place to run JavaScript and see what it prints. Type code in the editor, press Run, and read the output in the console panel next to it. It is useful for homework, checking an idea, or practising for interviews.

How to run JavaScript online

  1. Edit the starter code, or click an Example such as Loops or Promises and async.
  2. Press Run, or Ctrl + Enter.
  3. Read the Console output. Warnings show in orange and errors in red.
  4. Fix any error using the line number shown, then run again.
  5. Click Copy output to copy what was printed, or Reset to go back to the starter code.

Each run starts fresh, so variables from the last run are gone.

What the console shows

The console prints values in a readable form, like browser developer tools:

const students = [
  { name: "Ravi", marks: 82 },
  { name: "Sneha", marks: 91 },
  { name: "Arjun", marks: 67 },
];
const toppers = students.filter((s) => s.marks >= 80);
console.log("Toppers:", toppers.map((s) => s.name));

const average = students.reduce((sum, s) => sum + s.marks, 0) / students.length;
console.log("Average marks:", average.toFixed(2));

Output:

Toppers: ["Ravi", "Sneha"]
Average marks: 80.00

These console methods work: console.log, console.info, console.warn, console.error, console.table (printed as text), console.count, console.time and console.timeEnd, console.assert and console.clear.

Reading error messages

When something goes wrong, the console shows the error type, message and line:

const marks = [70, 80];
console.log(mark.length);

Output:

ReferenceError: mark is not defined (line 2)
Error Usual cause
ReferenceError: x is not defined Misspelt variable, or used before it was declared
TypeError: x is not a function Calling something that is not a function, often a typo in a method name
TypeError: Cannot read properties of undefined Reading a property of a value that is undefined
SyntaxError: Unexpected token A missing bracket, comma or quote. Nothing runs until it is fixed

Common mistake: A common mistake is sorting numbers with sort() alone. [10, 9, 1].sort() gives [1, 10, 9], because sort compares values as text by default. Use [10, 9, 1].sort((a, b) => a - b) to get [1, 9, 10]. Try it with the Objects and arrays example.

JavaScript quirks to try in the console

Code Output Why
typeof null object A long-standing bug kept for compatibility
0.1 + 0.2 0.30000000000000004 Decimal fractions are stored in binary
"5" + 3 53 + joins strings when one side is a string
"5" - 3 2 - always converts to numbers
NaN === NaN false NaN is not equal to anything, use Number.isNaN

Curious why 0.1 + 0.2 is not exactly 0.3? See how numbers look in binary with the number system converter.

Safe by design

Your code runs in a hidden <iframe> with sandbox="allow-scripts". It can run JavaScript, but it cannot read this site's cookies or storage, open pop-ups or change this page. Nothing is sent to a server. Need HTML and CSS too? Use the online HTML, CSS and JavaScript editor, which adds a live page preview.

Learn as you practise

Pro tip: Print a label with every value, like console.log("total:", total). When you have many log lines, labels tell you at a glance which value is which.

Frequently asked questions

Is this a real JavaScript compiler?
JavaScript is not compiled ahead of time like C or Java. Your browser's JavaScript engine runs the code directly, which is what people mean by an online JavaScript compiler. It supports modern JavaScript such as let, const, arrow functions, classes, promises and async/await.
Can I use Node.js features like require or fs?
No. The code runs in a browser, so Node.js modules such as fs, path and require are not available. Plain JavaScript, arrays, objects, strings, Math, Date, JSON, promises and timers all work.
Why is alert() not showing a popup?
Popups are blocked inside the sandbox. alert() prints its message to the console instead, prompt() returns null and confirm() returns false. Use console.log for output.
My page froze. What happened?
An endless loop, such as while (true) with no break, keeps the browser busy forever. Close and reopen the tab, then check your loop condition.
Is my code saved or uploaded?
No. Nothing is uploaded or stored. Copy your code into a file on your computer to keep it.

Try another tool

See all free tools
Chat with us