Style, CSV documenting etc.

Browser scripting
Site Admin
Posts: 178
Joined: Tue Sep 29, 2009 6:25 pm
Location: Moss Norway

Style, CSV documenting etc.

Postby KBleivik » Tue Aug 16, 2011 1:04 pm

1. Javascript best practices.

What is the best coding practice in one language may be bad in another language. Some suggest that you should not use tabs to ident code in JavaScript. Instead they mean that using two spaces is best. In PHP underscores is often used in variable names. In JavaScript the preferred method is camelCase. Here

Use the strong equality operator === instead of ==: ... beginners/ ... practices/

2. CVS - Concurrent Versioning System

Every JavaScript file should have a comment at the top that has the contents $Id$ like this

Code: Select all

// $Id$

Read more:

3. Document your JavaScript code.

One recommended way to comment your code is as shown in this add.js file


Code: Select all

 * Add two numbers together.

 *  Add two numbers.
 *  This function adds two numbers together and returns the sum.
 *  @param a
 *    The first number
 *  @param b
 *    The second number
 *  @return
 *    The sum of a and b
function sum(a,b) {
  return a+b;

Where we have added one comment for the file and one comment for the function. In addition, note the content $Id$ comment at the top.

For further information see: ... ion-tools/ ... javascript

Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest