-
- Variable is a named space in memory that stores a value.
- Variables can include characters or digits or both. But they cannot begin with digits.
- They cannot contain special symbols except underscore(_) or dollar sign($).
- We cannot use keywords as variables and they must be unique within a scope.
- They are case-sensitive and cannot contain spaces.
- Some examples of Identifiers are: firstName, last_Name, number1 etc.
- You should declare a variable using a data type before you use it.
- Use var keyword to declare a variable.
- For example: var value:string=”Hello”;
| var value:string=”Hello”; | Declaring a variable of a particular data type and storing a value in it. |
| var value:string; | Declaring a variable of a particular data type. As we are not assigning a value to it, by default undefined is assigned to it |
| var value=”Hello”; | Declaring a variable and storing a value in it. Data type of the variable is determined by the type of value stored in it. Hence it will be of string type |
| var value; | Declaring a variable. As nothing is specified, the data type will be any and value will be undefined |
One thought on “Variables in TypeScript”