Every programming language has some naming convention, JavaScript is no exception. It is good practice to follow naming conventions while naming variables, functions, classes and so on. Following are some naming convention used in JS-
Do not use reserved keywords:
Never user reserved keywords (like return, for, boolean etc) as variable name.
JavaScript variable names are case sensitive:
Be careful while naming variable. JS variables are case sensitive. For example – user and User are two different variables.
Do not start variable name with number:
In JavaScript variable name should start with an alphabet or special characters.
var 12user = 'Test' // Not valid
var _12user = 'Test' // This is valid
var _emailId= '[email protected]' // This is valid
Variables:
It is good to use small or camelCased name for variables and functions. Example :
var firstName = 'Developer'; // Good
var firstname = "Developer" // Bad
Functions:
//Good
function getName(){
// do something
}
//Bad
function name(){
// do something
}
Varun
Nice article. Keep it up.
Datatype
Thanks.