Clean Up Your JavaScript
This is a great tool that properly formats JavaScript code, making it easy to read and work with. With it you can clean up your own code, or take code from existing functions (like Dreamweaver behaviours) and decrypt them; inserting line breaks and tabs where it makes sense. Best of all, the tool is free!
This tool is similar to the 'apply source formatting' for HTML in Dreamweaver. It has several options:
- Take an input .js file, and output to a new, cleanly formatted file
- Open in Notepad
- Drag and drop
- Switch languages
- Insert new line before opening bracket (Visual Studio style)
- Insert tabs or spaces
Here's the example code cleanup from the author's website:
<script language="JavaScript">var i=0,s="",k=0;function foo()
{for(j=0;j<10;j++){for(i=0;i<10;i++){s="string1";
k=Math.floor(Math.random()*10);
for(i=20;i>9;i--){s="string2";k=i;}}}</script>
This gets run through the 'JavaScript Code Improver', and becomes:
<script language="JavaScript">
var i = 0, s = "", k = 0;
function foo()
{
for(j = 0; j < 10; j++)
{
for(i = 0; i < 10; i++)
{
s = "string1";
k = Math.floor( Math.random()*10 );
}
for(i = 20; i > 9; i--)
{
s = "string2";
k = i;
}
}
}
</script>
Much easier to read and work with! You can download the tool for free here. Note: while this tool does clean up and format obfuscated code, it may still be difficult to understand!


on December 11th, 2008 at 11:30 am
I downloaded the app and it works beautiful. Thank you!!
Mali
on February 15th, 2009 at 10:32 am
It's quite nice but it removes ALL comments, if it wouldn't do that, it would be perfect.
on March 17th, 2009 at 9:07 am
[...] P.S.: there is an utility "a great tool that properly formats JavaScript code". Very good for formatting files "editor_plugin.js" back for reading: http://www.justin-cook.com/wp/2006/04/04/clean-up-your-javascript/ [...]
on October 7th, 2010 at 2:58 pm
This tool is awesome, thanks alot for lettung us know there is a tool like this!
on May 4th, 2011 at 2:22 am
I am using this online tool for my js codes, xtreeme.com/javascript-optimizer/ and also checked with jshint.com, very helpful.