You found the code you needed. It sits in a browser console, or in the source of a minified page, and it clearly does the thing you are trying to understand. Then you copy it into your editor and the problem appears: the whole script arrives as one long line, or as a tangle of uneven spacing where statements run together with no visible structure. The code is complete, but in that shape it cannot be read, searched or reasoned about.

This is the everyday job of a formatter. This guide shows how to take code copied out of a console or a page source and make it readable with the free JavaScript Formatter on Ovatly, which beautifies compressed or messy JavaScript into consistently indented code, one statement per line. It also covers the one bit of cleanup worth doing by hand before you paste, because a formatter formats what you give it, nothing more.

Contents

  • Quick answer
  • Why console and page-source code arrives as a mess
  • Clean the paste before you format it
  • How to format copied JavaScript, step by step
  • Worked example: beautifying one-line code
  • Limitations and alternatives
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Copy the code out of the console or page source, remove any lines that are not code, such as result values or console prompts mixed into the output, then paste what is left into the JavaScript Formatter. Choose an indent size of 2 or 4 spaces, press Format JavaScript, and read the result one statement per line. Copy or download the formatted code when you are done. Only whitespace, line breaks and spacing around punctuation change; your logic is never changed.

Why console and page-source code arrives as a mess

Production JavaScript is shipped minified, which means it was deliberately compressed into as few lines as possible. View the source of a page and copy a function out of it, and you inherit that compression: hundreds of statements can sit on a single line, with no indentation to show where one block ends and the next begins.

Console copies have their own problem. What you select in a console is a transcript, not a clean file. Alongside the code you typed or inspected, the transcript can include the values the console printed back, prompts, and other output lines that were never part of the script. Pasted into an editor untouched, the transcript mixes code and results together, and neither a formatter nor a reader can tell them apart at a glance.

In both cases the code itself is usually fine. It is the layout that is broken, and layout is precisely what a formatter repairs.

Clean the paste before you format it

Spend a minute on the paste before formatting, because the formatter formats what you paste and does not fix syntax errors. Badly broken code may format strangely or be rejected, and lines that are not code at all count as broken code from the formatter's point of view.

Go through the copied text and delete anything that is not JavaScript: printed result values, console prompts, timestamps, warning lines, and any fragments left over from the page around the script you wanted. What remains should be the script itself, complete from its first statement to its last. If a section is missing because the copy was cut short, formatting will not invent it; go back and copy the missing part.

One more check matters. The formatter works on plain JavaScript, and JSX components and TypeScript annotations are not supported. Code copied from a console is usually plain JavaScript, but if what you grabbed is JSX markup or annotated TypeScript, it will not format properly here, and a parser-based tool in your editor is the better route.

How to format copied JavaScript, step by step

  1. Open the JavaScript Formatter and paste your JavaScript into the input box.
  2. Choose an indent size of 2 or 4 spaces. Match the convention your project already uses.
  3. Press Format JavaScript.
  4. Read the formatted code, one statement per line, then copy or download it.

Worked example: beautifying one-line code

Take the kind of compressed line a console or a minified source hands you:

function add(a,b){return a+b;}

Press Format JavaScript with a 2-space indent and it comes back as:

function add(a, b) {
  return a + b;
}

Nothing about the code changed: the same function, the same parameter names, the same addition, the same return. What changed is everything around it. The opening brace gets its own clear position, the return statement sits on its own line indented inside the function body, the closing brace lines up with the start, and spacing around the punctuation is consistent. Semicolons and braces are laid out in a standard style, so in a script a hundred times this size, the structure stays visible in the same way: each statement on its own line, each level of nesting one indent deeper.

One thing in a larger paste may surprise you: a template literal stays on one long line even after formatting. That is deliberate. Template literal contents are literal text, so the formatter leaves them exactly as written rather than guessing where breaks belong inside your string.

Limitations and alternatives

Formatting does not fix syntax errors. If the code you copied is genuinely broken, perhaps because the copy dropped a section, the output may be strange or the paste may be rejected. Repair comes first, formatting second.

Scope is the other limit. The formatter will format whatever you paste, but a large production bundle is better handled by your editor's formatter or a source map in devtools, which can recover the original files rather than a beautified approximation of the shipped one. For a snippet, a function or a modest script copied out of a console, the paste-in tool is the right size of solution.

And the support boundary bears repeating: plain JavaScript only. JSX and TypeScript are not supported, so code in those dialects needs a real parser first.

Common mistakes

  • Pasting the whole console transcript. Result values and prompts mixed into the code are not JavaScript. Delete those lines by hand before formatting, or the output will be strange.
  • Expecting the formatter to repair broken code. It changes whitespace, line breaks and spacing only. Missing or damaged sections stay missing and damaged.
  • Pasting JSX or TypeScript. Neither is supported. The formatter works on plain JavaScript, so convert first or use a parser-based tool.
  • Formatting an entire production bundle. It will run, but a source map in devtools gives you the original code, which is what you actually want at that scale.
  • Wondering why a template literal did not wrap. Its contents are literal text and are left exactly as written. That long line is correct behaviour, not a failure.

FAQs

Can it unminify a whole bundle? It will format whatever you paste, but a large production bundle is better handled by your editor's formatter or a source map in devtools.

Does formatting change my code's behavior? No. Only whitespace, line breaks and spacing around punctuation change.

Why did my template literal stay on one long line? Template literal contents are literal text, so the formatter leaves them exactly as written.

Will it fix syntax errors in code I copied? No. Formatting does not fix syntax errors; badly broken code may format strangely or be rejected.

Is my code uploaded anywhere? No. The formatter runs in your browser, so the code you paste never leaves your device.

Conclusion

Code you cannot read is code you cannot use, whatever its source. Clean the non-code lines out of the paste, run it through the JavaScript Formatter, and work with one statement per line and structure you can see into. When the readable version is ready to ship and you want it compressed again, the companion guide on minifying a small script without a build step covers that direction, and the rest of this series lives in the Developer Tools guides archive.