How to declare a variable in JavaScipt?
Variables are case sensitive and must start with an alphabhet letter or a underscore (_).
var lastName = "Funda";
myName = "Sheo";
var a = 20;
b = 30;
In the above code snippet
- The 1st line declares the firstName variable.
- The 2nd line declares the last name variable and assign value.
- 3rd line assigns a value to undeclared variable that automatically creates a valid variable and the scope of this variable would be thorugh out the page.
In function MyFunction
Views: 5655 | Post Order: 3
- a variable scope is within MyFunction only and we will not be able to access its value outside this function
- b variable scope will be complete page, whose value can be accessed anywhere in the page, even within other function