JavaScript Coding Guidelines



JavaScript Program Coding Guidelines:

  1. Always declare variable using var keyword, except when intentionally creating a global variable.
//var name=”Dhanik”;
  1. Always use semicolons at the end of statement. So that when minification will be done there will no lose of functionality.
  2. Constants should be uppercase, with each word separated by an underscore.
// var PI=2.147;
  1. Functions, variables, and method names all use camel case notation with the first letter lowercase.
//var empFirstName=”Dhanik”;
  1. Classes and enum names also use camel case notation but with the first letter uppercase.
  2. There should be proper spacing between statements. Use tabs to indent code. Don’t use white spaces at the end of lines and empty lines should not have spaces either. Below example illustrates the preferred spacing.
if ( name === “Dhanik” ) {
methodCall( “see”, “our”, “spacing” );
}
  1. Use proper comments. For multiple-line comments use /* */ and for single-line comments use //, with an empty line above the comment. The single-line comment precedes the comment that it refers to, and should be the only thing on the line.
// my comment
var name = ‘Dhanik;

var name = ’blah’; // bad
  1. Always use identity (===) comparison over simple quality (==). Simple equality should use when testing for null and undefined. Identity (===) equality will only check null.
  2. Use single quotes for string literals.

Comments

Popular posts from this blog

How to Add HttpModule in MVC5 Application

Map Routes using Route Class in MVC

How to convert a string with multiple comma separated values to rows in SQL Server