Part 2 - Learn about Variables in JavaScript Step by Step
Alert: Post is under development on 13-Aug-2021.
In the previous installment of the Variable, we learnt the following:
- Purpose of a variable,
- Creation of a variable
- Overview of usage of Interpreter, etc.
In this part, we are going to learn further. Let's read on.
What are other rules to create a variable?
Answer: Let's have a look at other rules to create a variable in JavaScript coding.
- We should use an 'underscore' (_)character to create a more legible
variable name. Eg.
let _productCategory; let employee_address_detail; let dropDownList_Open;
- We may use a combination of letters and digits. Eg.
let name5ThGrade = '5 (B)' let discount25P = '25%'
We should avoid using 'digits' & all special characters (except _ and $) as names for a variable. It is quite difficult to comprehend by an Interpreter of JavaScript language. The following is a big No in any programming language!
let first name = "Nikhil"; let first+name = "Nikhil"; let 2222 = 10;
Don't use it at all to save yourself from run-time errors. Errors halt our program/ application which is certainly an undesirable situation.
We are allowed to use a '$' character to name a variable. But it has a very special purpose in creating Java Script. Thus we must not until we know what we are doing.
- We use camelcase for creating variables in JavaScript. Eg.
Yes, you can declare more than one variable using a singlelet myVariable, productName, productCode, productPrice;
let
keyword.
What are other types of variables available in JavaScript?
Answer: Stay tuned