2. General Coding Principles
99% of code should be housed in external js files.
Include the file at the end of the BODY tag for maximum
performance.
All Boolean variables should start with "is".
isValid = (test.value >= 4 && test.success);
Minimize global variables - the less globals you create, the
better.
When specifying any global variable, clearly identify it
window.globalVar = { ... }
3. General Coding Principles
Name variables and functions logically:
For example: popUpWindowForAd rather than
myWindow.
Keep variables name meaningful.
Keep constants or configuration variables - at the top of the
document.
Comment your code!
4. White-space
keep one space after each comma and colon (and semi-
colon where applicable),
no spaces immediately inside the right and left sides of
parenthesis.
Which code is correct?
1.for ( var i = 0, j = arr.length; i < j; i++ ) 1.for(var i=0,j=arr.length;i<j;i++){
2.// Do something.
2.{
3.}
3.// Do something.
4.}
1.for (var i = 0, j = arr.length; i < j; i++) { 1.for(var i=0, j=arr.length;i<j;i++){
2.// Do something.
2.// Do something.
3.}
3.}
5. plugins.js and script.js
Plugins.js is meant to hold all of a sites plugin code.
./* PLUGIN DIRECTORY
What you can find in this file [listed in order they appear]
1.) Animate Background Position - http://plugins.jquery.com/project/backgroundPosition-Effect
2.) jQuery Easing Plugin - http://gsgd.co.uk/sandbox/jquery/easing/
3.) jQuery Ajax Form plugin - http://jquery.malsup.com/form/#download
4.) jQuery validation plugin (form validation) - http://docs.jquery.com/Plugins/Validation
-password strength
5.) Styled Selects (lightweight) - http://code.google.com/p/lnet/wiki/jQueryStyledSelectOverview
*/
Script.js is meant to hold your site or application code
6. Variables, ID & Class
variables - completely lowercase letter or camelCase.
id and class declarations in CSS - only lowercase.