JavaScript Playground
Free online JavaScript playground, run code in browser
About JavaScript Playground
An in-browser scratchpad for running a snippet of JavaScript and inspecting its console output. Your code is compiled with `new Function(code)` and executed synchronously; console.log, console.warn, console.error, and console.info are temporarily intercepted so their arguments are captured, formatted (objects JSON-stringified), and rendered in color by level. The tool also reports execution time in milliseconds and surfaces any thrown error in a red banner.
How to Use
1. Replace the default `// Write your JavaScript code here` text in the Code Input textarea with your own snippet. 2. Click Run. Execution time appears next to the button as `Executed in X.XX ms`. 3. Inspect the Console Output card: each captured call is shown on its own line, color-coded — log (foreground), warn (yellow), error (red), info (blue). Objects are pretty-printed as 2-space JSON. 4. If the snippet throws, the exception message appears in a red error banner above the Console Output card and no console output is shown for that run.
Execution Sandbox and Argument Formatting
Important behaviors to know before you rely on results: - Code is run via `new Function(code)()` in the page's real global scope — it is NOT a hardened sandbox. The tool itself warns about this with a yellow Security Warning banner. Do not paste untrusted code. - The four console methods are replaced for the duration of the run and restored in a `finally` block, so capture is scoped to your snippet only. - Argument formatting: `null` renders as the literal "null", `undefined` as "undefined", objects via `JSON.stringify(arg, null, 2)` (falling back to `String(arg)` if stringify throws, e.g. for circular structures), and primitives via `String(arg)`. Multiple arguments per call are joined with a single space. - There is no module/await support — async code will not block the timing measurement, and ESM `import` statements will throw.
▶Can I use async/await, fetch, or ES module imports?
▶Is it safe to run untrusted code here?
▶Why does my object print as [object Object] or fail to stringify?
▶Is my code sent to a server?
If this tool has been helpful to you, consider buying me a coffee.
Buy me a coffee