- Declaration and Initialisation
Declaration of variables late in the program is not at all a good practice. You should declare all the variable in the beginning of the program, it’s like taking out all your tools before starting a job. Declaration of all variables before getting into the code of you function gives easy access to and understandability of the program. Apart from declaration, it’s best to initialize your variables at the time of creation so that none are left undefined.
- Build Specialized Functions
- Crisp and Concise Code
- DOM manipulations
Accessing the DOM (Document Object Model) is important for getting the most out of your program and especially when it comes to complex programs. However, doing so repeatedly can cause visual clutter and might also slow down the program. A better option is to access it once and cache it for later use in a variable, this way you can access that variable instead of accessing the DOM again and again. You make the code visually cleaner and more efficient by accessing the variable in place of.
- Avoiding Global Variables
- Using Strict Mode