Developer Mise à jour de l'outil il y a 2 jours

Free JavaScript (JS) Formatter Online

JavaScript Beautify adds indentation and line breaks to a compact script so you can read it again. It works well on classic ES5 code, but it is not safe for every modern syntax feature; test the output before using it. Paste code or fetch a URL, then copy or download the result.

JS Formatter Beautify JS Readable Code Online Formatter

Utilisation Free JavaScript (JS) Formatter Online

Collez l'URL directe d'un fichier de code pour charger son contenu dans l'éditeur.

Résultat

Terminé
Lien vers l'outil
Copié dans le presse-papiers.
Aidez-nous à améliorer cet outil
68
Temps passé
70
Nombre total d'utilisateurs
5+ années
Servi
Dernière révision en il y a 2 semaines. Les chiffres d'utilisation sont mis à jour lors d'audits périodiques. (Rapports depuis 21 Feb 2022)
Signaler une incohérence

Lire le contenu

Découvrez comment fonctionne cet outil et dans quelles circonstances l'utiliser.

What this page is for

A minified script is one dense block of code. This page runs the source through a bundled JavaScript beautifier, which inserts line breaks, indents nested blocks with four spaces and spaces out operators. Comments are kept. The result is a readable copy that you can inspect, review or use as a starting point for a repair.

The page opens with JavaScript and Beautify already selected and accepts up to 200,000 characters per run. The beautifier is a legacy, ES5-oriented implementation, and that limitation matters. Read the section on modern syntax before you run it on a current codebase.

How the beautifier works

The script is tokenised and reprinted according to a set of formatting rules. Blocks such as functions, if statements, loops and classes receive a new line and an extra level of indentation. Operators receive surrounding spaces. A closing brace returns to the previous level. The output uses four spaces per level and does not add semicolons that were missing from the input.

Because it is a reprint rather than a parse-and-compile pass, it does not rename identifiers or evaluate expressions. It also does not check that the result is valid JavaScript. That is why the output must be tested, especially when the input uses syntax newer than the beautifier.

What it handles well

Classic function declarations, if/else chains, for and while loops, object literals, arrays, try/catch blocks and constructor functions all format predictably. Class declarations with fields and methods also format in testing. Line comments and block comments are preserved, which makes the output useful for understanding an unfamiliar vendor file.

A typical ES5 function comes back with the body indented, each statement on its own line and the braces aligned. That is enough to trace control flow and find a missing branch.

Where modern syntax breaks

This is the most important limitation on the page. The bundled beautifier does not understand several features that are common in modern JavaScript, and it can split their tokens into invalid code:

  • Arrow functions: the arrow token can be separated into an equals sign and a greater-than sign, which is not valid syntax.
  • Optional chaining: the question mark and dot can be separated by a space, changing the operator into something the engine rejects.
  • Nullish coalescing: the two question marks can be separated, with the same effect.
  • Template literals: an interpolation can be broken across lines and spaces, corrupting the string.

These are not cosmetic differences. The output may look plausible at a glance and still fail to parse. If the script contains any of these features, do not replace the original with the beautified copy. Use an editor or formatter that supports the syntax, and treat this page as unsuitable for that file.

JSX and TypeScript

JSX and TypeScript are not JavaScript. Angle-bracket components, type annotations, interfaces and generics use syntax the beautifier does not model. It may format parts of the file and corrupt others. Compile or strip the types first, or use a formatter built for those languages.

Comments are kept

Line comments and block comments survive the pass in testing, including a comment at the top of the file and a block comment at the end. That is useful when you are reading a vendored library and the license or explanation matters. It also means the output is not a minified file; it is a reading copy.

What it does not change

Identifiers, string contents, numeric literals and the presence or absence of semicolons are left alone. The beautifier does not add missing semicolons, remove dead branches, rename variables or convert syntax. If the input is already valid, the output should be the same program with different whitespace, provided the syntax is supported.

When to use it

Use it on an older vendor script that you need to inspect. Use it on a small ES5 file you inherited and want to step through. Use it when a stack trace points to a compact file and you need line breaks to find the relevant block. Do not use it as a commit-time formatter for a modern application, and do not use it on a file you cannot restore from version control.

Step by step

  1. Keep a copy of the original file. This is not optional when modern syntax may be present.
  2. Paste the script into Manual Code, or load it through the URL tab.
  3. Confirm the language is JavaScript and the mode is Beautify.
  4. Press Process Code.
  5. Scan the output for split operators, broken template strings and stray spaces before replacing anything.
  6. Copy the result, or download it as beautify-output.js.
  7. Run the output through a syntax check before using it.

Fetching a script from a URL

The URL tab downloads a public script on the server and places the response in the editor. The fetch is capped at 200,000 characters. CDN links usually work; authenticated or bot-protected links usually do not. The server fetches the raw response, so an HTML error page will fail to format as JavaScript.

Checking the output

The quickest check is a syntax parser. Save the output as a .js file and run it through Node with the check flag, or paste it into a browser console inside a try block. A parse error tells you the beautifier broke the file. If it parses, compare the behaviour with the original on a test page; formatting should not change behaviour, but token splitting can change meaning before it changes syntax.

Working from a stack trace

A production stack trace gives a line and column in a compact file. After beautifying, the line numbers change, so use the column and the surrounding tokens to find the frame. Search for a distinctive string from the trace, such as an error message or a function name that survived minification. This minifier does not rename identifiers, so a function name from the trace is usually still searchable. Once you find the block, read upward to see which branch called it.

Formatting a fragment

You do not have to paste the whole bundle. If you only need to read one function, copy that function plus any helper it calls into the editor. A smaller input is easier to check and less likely to hit an unsupported construct. Keep the fragment in a scratch file and never paste the formatted fragment back into the bundle.

Limits

One script per run, 200,000 characters, JavaScript mode on this page. Processing happens on the server and the result is returned; it is not stored. The tool does not lint, type-check, transpile or guarantee that the output is valid for modern engines.

Frequently Asked Questions

FAQ

Des réponses succinctes aux questions que se posent les utilisateurs avant de se fier au résultat.

The bundled beautifier is ES5-oriented and can split the arrow token. Keep the original and use a modern formatter for files that use arrow functions.

No. It can separate the question mark and dot, producing invalid code. Do not use the output on a script that relies on optional chaining.

Yes. Line and block comments survived in testing, which makes the output useful for reading vendor code.

No. It reprints the tokens and does not insert semicolons. If the input relied on automatic semicolon insertion, the output keeps the same structure.

No. Those languages use syntax the beautifier does not understand. Compile them first or use a language-specific formatter.

Only after a syntax check and a behaviour comparison. For modern syntax the answer is usually no; for ES5 code it is usually yes.

It is sent to the server for formatting and returned in the response. The tool does not store it.

Commentaires (0)

Pour les discussions entre utilisateurs, les cas particuliers et les conseils complémentaires.
Laisser un commentaire
Votre commentaire sera visible par tous après sa publication.
Aucun commentaire pour l'instant. Soyez le premier à laisser un commentaire !
Faites-le-nous savoir !
Signaler un problème avec cet outil

Décrivez le problème que vous avez rencontré afin que nous puissions l'examiner et améliorer l'outil.

Ce qui aide le plus
Veuillez indiquer la saisie effectuée, le résultat attendu, le résultat obtenu, le navigateur ou l'appareil utilisé, ainsi qu'une capture d'écran si cela peut être utile.
Le bouton « Capture d'écran » permet de capturer la page affichée dans le navigateur et d'ajouter l'image générée à ce formulaire.
Capture d'écran en pleine page
Capturé dans votre navigateur avec newisty.
Aucune capture d'écran n'a encore été réalisée.
Outil Rapport