JavaScript Code Runner
Write and execute JavaScript directly in your browser with full console output and error handling
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
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.
const data = [1, 2, 3];
const fake = "1,2,3";
console.log(Array.isArray(data));
console.log(Array.isArray(fake));
true
false
Flattening a Nested Array
You pulled data from multiple endpoints and ended up with arrays inside arrays. Time to flatten.
const nested = [[1, 2], [3, [4, 5]], [6]];
const flat = nested.flat(Infinity);
console.log(flat);
console.log("Count:", flat.length);
[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.
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");
ℹ Only 'c' will fire after 200ms
fired: c
Who Uses This
Testing small functions before dropping them into a project — regex patterns, date formatting, prototype methods.
Running homework exercises and experimenting with loops, conditionals, and array methods without setting up a dev environment.
Practicing algorithm problems — sorting, string manipulation, tree traversal — with instant feedback on output.
Verifying that code examples in tutorials and docs actually produce the output they claim.
Common Mistakes
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.
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.
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
- Processing: 100% client-side — code never leaves your browser
- Execution: Sandboxed via the Function constructor
- JS Support: Whatever your browser supports (ES6+, async/await, Fetch, etc.)
- Console Methods: log, warn, error, info, table
- Browser Support: Chrome, Firefox, Safari, Edge
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.