Home › Developer Tools › JavaScript Online Compiler

JavaScript Online Compiler

Write JavaScript and run it instantly. Output appears in a built-in console with tables, objects and timings, errors point to the exact line, and runaway loops are stopped automatically. Share your code with a link.

Last updated:

main.js
Ln 1, Col 1Ctrl + Enter to run · Tab indents
Console
Ready

Code runs in an isolated Web Worker on your device: no DOM (document, window), but full modern JavaScript, timers, promises, fetch and top-level await.

Advertisement
Advertisement

How to use the JavaScript Online Compiler

  1. Write or paste JavaScript in the editor, open a .js file, or pick an example.
  2. Press Run code or Ctrl + Enter. Output from console.log and friends appears in the console on the right.
  3. Fix errors by clicking the line link in an error message to jump to that line in the editor.
  4. Stop long runs with the Stop button; infinite loops are stopped automatically at the time limit.
  5. Share or save your code with Copy share link or Download.

Console methods you can use

MethodWhat it showsExample
console.log()Values separated by spaces; objects are formatted and nested up to 4 levelsconsole.log('total', 42, {a: 1})
console.info() / debug()Like log, marked as info or dimmedconsole.info('ready')
console.warn() / error()Yellow or red lines, counted in the status barconsole.warn('low stock')
console.table()Arrays or objects as a table; optional column listconsole.table(users, ['name'])
console.time() / timeEnd()Elapsed milliseconds for a labelled blockconsole.time('sort')
console.count()How many times a label was reachedconsole.count('retry')
console.group() / groupEnd()Indents the following linesconsole.group('Step 1')
console.assert()An error line only when the condition is falseconsole.assert(x > 0, 'x must be positive')
console.dir() / trace()An object, or the current call stackconsole.trace('here')
Format specifiers%s string, %d/%i integer, %f float, %o/%O objectconsole.log('%s is %d', 'Ann', 30)

How your code runs

When you press Run, the code is first checked for syntax errors. It is then loaded as a classic script into a fresh Web Worker, a background thread with its own global scope. Every run starts clean, so variables from a previous run never leak into the next one. Top-level let, const and function declarations behave like a normal script, and code that uses await at the top level is wrapped in an async function automatically.

The console calls inside the worker are forwarded to the page, together with the line that produced them, and uncaught errors are mapped back to main.js line numbers. The page also sends the worker a heartbeat several times per second. If the code never yields, for example in while (true) {}, the heartbeat goes unanswered and the worker is terminated at the time limit, while the editor stays responsive the whole time.

Tips

  • Use Ctrl + Enter (Cmd + Enter on Mac) to run without leaving the keyboard. Tab and Shift + Tab indent and outdent selected lines.
  • Click the main.js:line label next to any console line to jump to the code that printed it.
  • Compare algorithms with console.time(), and run them a few times: the first run is often slower because the engine has not optimised the code yet.
  • Floating-point results such as 0.1 + 0.2 = 0.30000000000000004 are normal IEEE 754 behaviour, not a bug in the compiler. Use toFixed() or integer cents for money.

Frequently asked questions

Is JavaScript compiled or interpreted?

Both, in a sense. Modern engines such as V8 (Chrome, Edge, Node.js), SpiderMonkey (Firefox) and JavaScriptCore (Safari) parse your code, run it in an interpreter and compile frequently used parts to machine code just in time. This tool uses your browser's own engine, so the code runs exactly as it would in a script on a web page.

Why is document or window not defined?

Your code runs in a Web Worker, an isolated thread without access to the page. That keeps the editor responsive and lets infinite loops be stopped safely, but there is no DOM. Plain JavaScript, timers, promises, fetch, JSON, Math, Intl and typed arrays all work. To test code that changes HTML, use the HTML Editor.

What happens if my code has an infinite loop?

The page keeps working because the code runs in a separate thread. When the run exceeds the time limit you chose (5 seconds by default) the worker is stopped and the console explains that the code never paused. You can also press Stop at any time.

Can I use await, promises and timers?

Yes. Top-level await is supported, and the run stays active until all timeouts, intervals, fetch requests and the main async code have finished, up to the time limit. Uncaught promise rejections are reported as errors.

Can I import npm packages or use require?

Not directly. The code runs as a classic script, so import statements and Node.js require are not available. Node-only APIs such as fs and process are also missing. For browser-ready libraries you can use importScripts('https://...') with a full URL.

How do share links work, and is my code private?

The share link stores your code, compressed, after the # in the URL. That part is never sent to a server, so the code stays between you and the people you send the link to. Opening a shared link loads the code but does not run it until you press Run.

How accurate is the execution time?

The time shown is measured with performance.now() around your script, so it includes parsing and running but not page overhead. Timings vary between runs and browsers; use console.time for parts of your code and compare several runs.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

HTML Editor (Live Preview)Write HTML, CSS and JavaScript and see a live, sandboxed preview as you type.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.ESLint Config GeneratorGenerate a flat eslint.config.js for JavaScript, TypeScript, React or Node with rule presets.Is JavaScript Enabled TestCheck instantly if JavaScript is enabled, see your JS engine and get how-to-enable steps.Online Python CompilerRun Python 3 in your browser with input(), numpy, pandas, charts and share links.JSON EditorEdit JSON in a tree and as code side by side: add, rename, drag, change types, undo and download.Unzip FilesOpen and extract ZIP files online.RAR & 7z ExtractorOpen RAR, 7z and other archives online and extract files.Regex TesterTest and debug regular expressions live.File Info ViewerCheck file size, type, date and MD5/SHA hashes.SQLite ViewerOpen .db and .sqlite files in your browser, browse tables and run SQL queries.DOCX ViewerOpen and read Word .docx files in your browser, then print or save them as HTML.EPUB ReaderOpen and read EPUB e-books in your browser with pages, a table of contents and font controls.What Is My BrowserSee your browser, version, OS, engine, screen and which web features it supports.Font ViewerPreview TTF, OTF, WOFF and WOFF2 fonts with sample text, waterfall, glyphs and metadata.Markdown EditorWrite Markdown with a toolbar, live split preview, autosave and .md or HTML export.Regex Cheat Sheet75+ ready-to-use regex patterns for emails, URLs, IPs and dates, each with a live test box.JavaScript Keycode FinderPress any key to see its JavaScript key, code, keyCode, which, location and modifiers.QR Code ScannerScan QR codes with your camera or from an image and safely read the link or text.RAID CalculatorUsable capacity, efficiency and fault tolerance for RAID 0, 1, 5, 6, 10, 50 and 60 arrays.JSONPath TesterTest JSONPath expressions live: filters, slices, wildcards and recursive search, with matches highlighted.Mermaid Diagram EditorWrite Mermaid code and see flowcharts, sequence, Gantt and ER diagrams live. Export SVG or PNG.Country Codes ListSearch ISO 3166 alpha-2, alpha-3 and numeric country codes with calling codes and TLDs.CSS Selector TesterTest CSS selectors on your HTML: highlighted matches, match count and specificity.Git Cheat SheetSearchable Git command reference by task, with copy buttons and an undo/rename/fix wizard.HAR File ViewerOpen a .har file to see a waterfall timeline, headers, bodies, timings and size totals.jq PlaygroundRun jq filters on JSON in your browser with live output, flags and an example library.Markdown Cheat SheetInteractive Markdown syntax reference: edit every example and see the live rendered preview.Regex ExplainerPaste a regular expression and get a plain-English breakdown, railroad diagram and flag notes.XPath TesterTest XPath expressions on XML or HTML: highlighted matches, node paths, values and examples.EML File ViewerOpen .eml email files to read the message, headers and raw source and save attachments.Graphviz Online ViewerWrite Graphviz DOT code and render graphs live; switch layout engines, export SVG or PNG.Jupyter Notebook ViewerOpen .ipynb files and read code, Markdown, math, tables, plots and errors without Python.LaTeX Table GeneratorEdit a table like a spreadsheet or paste from Excel and get LaTeX tabular or booktabs code.Log File ViewerOpen huge log files with level colors, regex and time filters, JSON pretty-print and tail -f.Logic Gate SimulatorBuild logic circuits with AND, OR, NOT, XOR gates and flip-flops; see live outputs and truth tables.Online Code EditorVS Code-style editor in your browser: tabs, 50+ languages, find/replace, autosave.Online Hex EditorOpen any file as hex and ASCII, edit bytes, search, inspect values and save the result.PHP Online CompilerRun PHP 8 code in your browser with output, HTML preview, error lines and share links.PlantUML EditorWrite PlantUML and see sequence, class, activity and more diagrams live. Export SVG or PNG.Sorting Algorithm VisualizerWatch bubble, insertion, merge, quick, heap and radix sort step by step with live counters.Lottie ViewerOpen Lottie JSON or .lottie files to play, pause, scrub frames, change speed and see details.Diff ViewerPaste a git diff or .patch file and view it side by side or inline, with file navigation.EditorConfig GeneratorBuild an .editorconfig with indent, charset, line endings and trim rules per file pattern.Folder Compare ToolCompare two folders by file list, size and SHA-256 hash, then open a text diff of changed files.Glob Pattern TesterTest glob patterns like **/*.js, {a,b} and !exclusions against a list of file paths.JMESPath TesterEvaluate JMESPath expressions against JSON live, the query language used by the AWS CLI.MongoDB Query TesterTest MongoDB find filters, projections and aggregation pipelines on sample JSON documents.Semantic Version CalculatorBump, compare, sort and test SemVer versions against npm ^, ~ and x ranges.XSLT TesterRun an XSLT 1.0 stylesheet on XML in your browser and see the output as HTML, XML or text.ASCII Diagram EditorDraw boxes, arrows and text on a character grid and copy plain-text diagrams for code and READMEs.DBF File ViewerOpen dBase .dbf files and shapefile tables, search and sort records, export CSV or XLSX.MBOX File ViewerOpen .mbox mail archives: list and search messages, read them, save attachments, export EML.MDB File ViewerOpen Access .mdb and .accdb databases in your browser: list tables, view rows, export CSV.Shapefile ViewerView zipped shapefiles on a map with the attribute table, then export to GeoJSON or CSV.MSG File ViewerOpen Outlook .msg emails in your browser: sender, recipients, body, headers and attachments.
See all 53 Code Playgrounds & Testers →