11. Use shortcut declarations
- Use {} instead of new Object()
- Use "" instead of new String()
- Use 0 instead of new Number()
- Use false instead of new Boolean()
- Use [] instead of new Array()
- Use /()/ instead of new RegExp()
- Use function (){} instead of new function()
12. Avoid Global Variables
Minimize the use of global variables.
This includes all data types, objects,
and functions.
Global variables and functions can be
overwritten by other scripts.
Use local variables instead, and learn
how to use closures.
13.
14. Always Declare Local Variables
All variables used in a function should
be declared as local variables.
Local variables must be declared with
the “var” keyword, otherwise they will
become global variables.
15. Long List of Variables?
Omit the "Var" Keyword and
Use Commas Instead
16.
17. Say “No!” to loops declarations
Do not declare variables inside loops,
don't make the engine work any harder
than it must.
18.
19. End Your Switches with Defaults
Always end your switch statements
with a default. Even if you think there
is no need for it.
20. Avoid Cluttering The Global
Namespace
Using globals may cause naming conflicts
between javascript source files and cause
code to break. For this reason, it is a good
practice to encapsulate functionality within
a single global namespace.
21. Avoid sync "Ajax" calls
If you think that your situation requires
sync mode, it is most likely time to
re-think your design. Very few (if any)
situations actually require Ajax requests
in sync mode.
22. Use JSON
When storing data structures as plain
text or sending/retrieving data structures
via Ajax, use JSON instead of XML
when possible.