1) Try to avoid too many DOM manipulations
By avoiding DOM manipulations, you will greatly improve your code’s performance.
Here’s the quick way:
Here’s the slow way:
This example demonstrates that the DOM is modified only once, instead of 50 times.
2) Better binding actions with functions
Here’s a code example:
The quick method is much better for performance, as the action is bonded to only one element instead of 3.
3) Use short form of declaration variables
This will improve the readability of your code for you and other developers.
4) Use a ternary operator when it’s more appropriate
Better user ternary operator in this case:
Now you have 2 lines of code instead of 16.
5) Avoid deep "if" statements
Here is a better way of representing this function:
This method is much more readable and easier to understand.
6) Keep jQuery objects in variables
This will save one DOM manipulation and improve the readability of your code
7) Don't overuse with variables