JavaScript is untyped language. So, JavaScript variable can hold a value of any data type. Therefore , during variable declaration you don't have to tell JavaScript the type of value that variable will hold.
Note that,
- Variable must be start with a upper case letter, lower case letter or underscore. As an example we can declare variable as follows;
- name
- Name
- _name
- Number is not allowed to use as the first character of variable
- Can't use spaces in variables
- Not allowed to use JavaScript keywords such as var, function etc
- Variable name is case sensitive
Variables are declared with the var keyword as follows.
var name ;
Then variable can be initialized as,
name = "Sanduni";
We can declare variable and assign value in same line by
var name = "Sanduni";
As an example,
This is the result we got

No comments:
Post a Comment