JavaScript Playground
Write and run JavaScript code directly in your browser with a built-in console, DOM preview, and code snippets
Write JavaScript, hit Ctrl+Enter, and get instant console output with expandable objects and a live DOM preview — no signup, no bloated IDE, no waiting. Built-in snippets cover array methods, async/await, Canvas, and more, while infinite loop protection kills runaway code after 3 seconds. And everything runs in your browser. Nothing gets uploaded.
How It Works
When you press Run, the playground wraps your code in a sandboxed iframe with a custom console implementation. Every console.log, warn, error, and table call gets intercepted and rendered in the output panel with proper formatting — objects show up as collapsible JSON trees. The DOM preview panel gives you a live view of anything your code writes to the document, so you can test createElement, innerHTML, or Canvas drawing without switching tabs.
Examples
Quick Array Filtering
Testing whether filter + map chains work the way you think before adding them to production code.
const prices = [12.5, 0, 99, -3, 45.2, 0];
const valid = prices
.filter(p => p > 0)
.map(p => `$${p.toFixed(2)}`);
console.log(valid);
["$12.50", "$99.00", "$45.20"]
Debugging an Async Function
You’re not sure if your async/await logic resolves in the right order. Easier to test here than add console.log lines to your actual app.
async function fetchData() {
console.log("start");
await new Promise(r => setTimeout(r, 500));
console.log("after 500ms");
return { status: "ok" };
}
fetchData().then(r => console.log(r));
"start"
"after 500ms"
{ status: "ok" }
DOM Manipulation Preview
Building a quick UI prototype — create elements and see them render live in the DOM preview panel.
const btn = document.createElement("button");
btn.textContent = "Click me";
btn.style.cssText = "padding:10px 20px;background:#6366f1;color:#fff;border:none;border-radius:6px;cursor:pointer;";
btn.onclick = () => btn.textContent = "Clicked!";
document.body.appendChild(btn);
A styled purple button appears in the DOM Preview panel. Clicking it changes the label to "Clicked!"
Who Uses This
Testing regex patterns, API response parsing, or algorithm logic without spinning up a project.
Working through homework exercises and seeing output instantly — no install, no setup.
Sharing code examples via URL during lessons so students can run them in one click.
Verifying that code samples in documentation actually produce the output they claim.
Common Mistakes
A while(true) with no exit will trigger the 3-second timeout and kill execution. Add a counter or break statement. The console will show an error if your code gets cut off.
This runs in the browser. Calls like require(), fs.readFile(), or process.env will throw ReferenceError. Stick to browser-native JavaScript and Web APIs.
If you use document.write() or create elements, output won’t show in the console. Switch to the DOM Preview tab in the bottom-right — that’s where visual output goes.
Technical Details
- Processing: 100% client-side — code never leaves your browser
- Browser Support: Chrome, Firefox, Safari, Edge
- Storage: Code auto-saves to localStorage
- Timeout: 3-second execution limit prevents frozen tabs
- Console Methods: log, warn, error, info, table, clear, time/timeEnd, count, group/groupEnd, assert
Frequently Asked Questions
Is my code saved between sessions?
Yes. Every keystroke gets saved to your browser’s localStorage automatically. Come back tomorrow and your code is right where you left it. Nothing is sent to a server — it’s all local to your machine.
What happens if I write an infinite loop?
The playground kills execution after 3 seconds and shows an error in the console. Your browser tab won't freeze. Fix the loop condition and run again — no need to reload the page.
Can I use fetch() or other Web APIs?
Most browser APIs work fine — fetch, setTimeout, Promise, Canvas, the DOM. What won’t work is Node.js-specific stuff like require() or fs. If the API runs in a normal browser tab, it should run here too.
How do I share my code with someone?
Hit the "Share URL" button. It encodes your code into the page URL. Copy that link and send it — when they open it, your exact code loads in their editor. No account needed.
Does console.table() work here?
It does. Pass an array of objects and you’ll get a formatted table in the console panel. Also supported: console.group(), console.time(), console.count(), and console.assert(). Objects render as collapsible trees with color-coded values.