Refactor to Simplify Code
Refactoring is the art of reworking your code to a more simplified or efficient form in a disciplined way. Refactoring is an iterative process:
Write correct, well-commented code that works.
Get it debugged.
Streamline and refine by refactoring the code to replace complex sections with shorter, more efficient code.
Mix well, and repeat.
Refactoring clarifies, refines, and in many cases speeds up your code. Here's a simple example that replaces an assignment with an initialization. So instead of this:
function foo() { var i; // .... i = 5; }
Do this:
function foo() { var i = 5; // .... }
For More Information
Refactoring is a discipline unto itself. In fact, entire books have been written on the subject. See Martin Fowler's book, Refactoring: Improving the Design of Existing Code (Addison-Wesley, 1999). See also his catalog of refactorings at http://www.refactoring.com/.