Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

JavaScript Code Runner

Write and execute JavaScript directly in your browser with full console output and error handling

Your files never leave your browser
Code runs in your browser. Avoid infinite loops.
Code0 chars, 0 lines
Console OutputReady
Press Run or Ctrl+Enter to execute your code
Ready·

Paste or write any JavaScript snippet, hit Ctrl+Enter, and see color-coded console output in the panel on the right — logs, warnings, errors, all with timestamps. Beats opening DevTools for a quick test because your code stays put instead of vanishing when you close the tab. And everything runs in your browser. Nothing gets uploaded.

How It Works

Write Code
➔
Execute in Sandbox
➔
See Console Output

Your code gets wrapped in a sandboxed Function constructor and executed directly in the browser's JavaScript engine. The runner intercepts console.log, console.warn, console.error, and console.table calls, then pipes them into the output panel with timestamps and color coding. If something throws, the error message and line number appear in red so you can spot the problem fast.

Examples

Checking if a Value is an Array

Quick sanity check — you're getting data from an API and need to confirm it's actually an array before calling .map() on it.

INPUT
const data = [1, 2, 3]; const fake = "1,2,3"; console.log(Array.isArray(data)); console.log(Array.isArray(fake));
OUTPUT
true false

Flattening a Nested Array

You pulled data from multiple endpoints and ended up with arrays inside arrays. Time to flatten.

INPUT
const nested = [[1, 2], [3, [4, 5]], [6]]; const flat = nested.flat(Infinity); console.log(flat); console.log("Count:", flat.length);
OUTPUT
[1, 2, 3, 4, 5, 6] Count: 6

Debounce Function from Scratch

Interview prep or just refreshing your memory on how debounce actually works under the hood.

INPUT
function debounce(fn, ms) { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => fn(...args), ms); }; } const log = debounce((x) => console.log("fired:", x), 200); log("a"); log("b"); log("c"); console.info("Only 'c' will fire after 200ms");
OUTPUT
ℹ Only 'c' will fire after 200ms fired: c

Who Uses This

👨‍💻 Developers

Testing small functions before dropping them into a project — regex patterns, date formatting, prototype methods.

🎓 Students

Running homework exercises and experimenting with loops, conditionals, and array methods without setting up a dev environment.

📚 Interview Prep

Practicing algorithm problems — sorting, string manipulation, tree traversal — with instant feedback on output.

✍️ Technical Writers

Verifying that code examples in tutorials and docs actually produce the output they claim.

Common Mistakes

Writing an infinite loop

A while(true) with no break condition will freeze your browser tab. The runner has a timeout, but heavy loops can still lock things up before it kicks in. Always add a counter or exit condition.

Expecting Node.js APIs to work

This runs in the browser, not Node. Calling require(), fs.readFile(), or process.env will throw a ReferenceError. Stick to browser-native APIs — fetch, DOM methods, and standard built-ins.

Modifying the page DOM directly

You technically can access document.body, but changing it will break the tool's own interface. If you want to experiment with DOM methods, log the results to the console instead of writing to the page.

Technical Details

Frequently Asked Questions

Is it safe to run JavaScript code online?

Yes. Your code runs in a sandboxed function inside your own browser — nothing gets sent to a server. It can't access your file system or other tabs. The main risk is writing an infinite loop that freezes the tab, but the runner includes a timeout to catch most of those.

Can I use async/await in the code runner?

You can write async functions and call them. Top-level await won't work directly since the code is wrapped in a regular function, but wrapping your code in an async IIFE — (async () => { ... })() — works perfectly.

Why is my console.log not showing anything?

Make sure you actually clicked Run or pressed Ctrl+Enter. If your code runs but produces no output, check that you're calling console.log() and not just assigning values to variables. A function that returns a value without logging it won't show anything in the console panel.

Can I make HTTP requests with fetch?

Yes, the Fetch API is available since the code runs in a real browser context. Keep in mind that CORS rules still apply. If you're fetching from an API that doesn't allow cross-origin requests, you'll get a network error in the console.

Does this support ES6 modules and import statements?

Import/export statements won't work here because the code isn't loaded as a module. You can use all other ES6+ features though — arrow functions, destructuring, spread operators, template literals, classes, Map, Set, Promise, and everything else your browser supports natively.

Share: