Rules for Creating a Variable in JavaScript



Hello Everyone in this post I am going to tell the basic rule which should be kept in mind before creating variables. This rules are almost same for php and other programing languages

In JavaScript, a variable can be created like this
var variableName,
in which var is a JavaScript keyword for creating a variable followed by variable name.
But there are a few simple rules which should be kept in mind before creating variables those rule are as follows:

1.Variable names must begin with a letter, $, or _ :-

In simple words variable name should not begin with number or any punctuation: except $ and _. but we may put number at other place except at beginning eg var car and car2 both are valid variable.

 

2.Variable names can only contain letters, numbers, $, and _.

Variable name can’t have space or special character such as !#%^& except $ and _

 

3.Variable names are case-sensitive.

Variable names are case-sensitive means variable var car and var CAR are different and they may have different-different values.

 

4.Avoid keywords.

Some words in JavaScript are keyword such as var which are used to create variable so these keyword should not be used to create variables

 

Stay tuned for the PHP Magento, WordPress, JavaScript and Magento2 latest tutorial and updates, Hope you enjoyed reading, if you need the professional Magento Development / PHP we can help you, just Click on the Link and send me your requirements.

Please Like the Post on Facebook or Google+.