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 ==: http://net.tutsplus.com/tutorials/javas ... beginners/
http://dev.opera.com/articles/view/java ... practices/
http://www.javascripttoolbox.com/bestpractices/
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$
3. Document your JavaScript code.
One recommended way to comment your code is as shown in this add.js file
add.js
Code: Select all
//$Id$
/**
* 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;
}
For further information see:
http://metajack.wordpress.com/2008/07/0 ... ion-tools/
http://www.stack.nl/~dimitri/doxygen/
http://www.stack.nl/~dimitri/doxygen/helpers.html
http://jayxie.com/doxygen-js/use-doxyge ... javascript