It doesn’t matter whether you are working on a home based project, a large corporate project for the company you work for or even if you are a freelance developer. The importance of clean code goes without saying.
Your ability to suitably maintain your code will rely on how much your earlier inserted code to hack and slash your way to something that works (especially for those head scratcher functions you never thought possible). This even goes for improperly named or placed variables and methods.
JS had to “look like Java” only less so, be Java’s dumb kid brother or boy-hostage sidekick. Plus, I had to be done in ten days or something worse than JS would have happened – Brendan Eich
If your reading this in retrospect, then the below (none-exhaustive) bulleted checklist will help you clean up your code:
Now the negative stuff is out of the way. Here are some tips on organising your code once you’ve cleaned it up a bit:
Simple, don’t dump all your code into one big JS file. Think about sectioning it off into separate files based on functionality type.
This is more applicable when working with more than one person or a larger in a team. If something breaks along the way of the project, it’s much easier to backtrace and fix it!
There are some great tools out there like JSLint fo example that can help ensure that your code works properly. One small mistake may go unnoticed in some browsers (not so in Internet Explorer), but several will end up breaking your code and you’ll have no idea how it happened until it’s too late.