How to format JavaScript
- Paste your code into JavaScript, such as a minified file or a snippet copied from your browser.
- Keep Format selected and choose 2 or 4 spaces. Choose Minify to compress the code instead.
- Copy the result or download it as a .js file.
What formatting changes
- Each statement goes on its own line, and blocks inside braces are indented one level.
- Spaces are added around operators and after commas and keywords, so
if(a>b){becomesif (a > b) {. - Blank lines you had are kept, but several in a row become one.
- Names, strings, comments and the order of the code don’t change.
Reading third-party code
Formatting is the quickest way to read a minified script: a library bundle, a tracking snippet or code you found while debugging a site. Once it’s indented you can follow the control flow, even with one-letter variable names. Minified code is not hidden code, so anything shipped to the browser can be read this way.