javascript Rules jbwyatt.com


Class JavaScript Rules

* Google JavaScript Style Guide *

CODE LOCATION ============= functions should either be in the header of the htmnl file OR (more likely) in an external file with a link from the html file VAR === All variables must be declared with 'var' before being used. - do not re-declare variables - do not re-declare parameters Avoid using global variables (declared outside of any function), unless necessary. Only use a variable for ONE TYPE. STATEMENTS ========== All statements must end with a semi-colon. Loop using: for, while, do while Branch using: if, if - else, if - else if - else FUNCTIONS ========= Unless there is some reason, all javascript code should be in functions. Use parameters to pass information INTO functions (not globals unless needed). Use the retun mechanism to pass information OUT of functions. OUTPUT ====== simple output at load time may use document.write complex output involving dynamic changing of web pages will use: document.GetElementById(id tag) + the innerHTML property (to change / augment html) + the style property (to change css)