Rules / Guidelines
Basic Guidelines and Rules
Basic rules of where to put the code:
- case is significant - use lowercase except for vars or functions which can be named in camel case e.g. getElementById or with underscores e.g. calc_square_root(16);
- no spaces in variable or function names
- one statement per line and end each line with semicolon (for clarity)
- comment to clarify intent - use // at start of each comment line
- name functions and variables in a meaningful way
- don't use these reserved names for your variables or functions:
abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void while with
- Escape sequences - a backslash "\" causes the character after it to have special meaning:
- \n is like a <br> in html, it creates a new line; \b backspaces one character
- \\ is how you get a "backslash" in your string. If you want to print the text string \folder\otherfolder you would have to type
string = "\\folder\\otherfolder" in the code
- \' or \" means print the quote instead of ending the string. For example if you want to print the text
She said "You're the greatest"!
the code would be
string = "She said \"You\'re the greatest\"!"
without the escape character the string would end before the word "You're" because of the double quote just before "Y"
Page Updated 12.08.2009