JCL's Tutorial On JavaScript Style
Usually a beginning programmer crams all the JavaScript code together making it difficult for his/her visitor to understand the document source. That is why good style is important in any type of programming. Do the tips listed below in your JavaScript code, not on your page. For example, when you double space, double space each line in the source, do not use the "\n" (new line) command twice to double space. Below are the guidelines that you should try to follow when creating your web page:
- Use a semicolon at the end of every command that does not end with a "{" or begin with a "}".
- Double space every command except the <script language = "JavaScript"> tag and "<!-- Begin hiding here --" command and the "// -- End hiding here -->" command and </script> tag.
- When using a command that ends with "{", place the "{" on the line following the command.
- Tab everything between "{" and "}" and add an extra tab for each "{" and "}" a command is surrounded by beyond the first.
- Put each HTML command in its own document.write().
- If your code is long and complicated, it may be good to insert a comment every once in awhile to explain what a command or group of commands does.
- Make it look neat. If it looks neat and it's easy to read, you did a good job.
That's about it. I know, that was probably the shortest and dumbest tutorial you've ever read, but good style is important. If you haven't learned that by now, you'll learn it later on.
JCL's HTML & JavaScript Tutorial
E-Mail Me