JavaScript variables
What are JavaScript Variables?
JavaScript variables can be considered as containers which stores a particular value or name for a particular block of memory.
In JavaScript we can assign variables with any of these 3 keywords var, let, const.
In JavaScript any data-types can be assigned to variables. If you assign a number to a variable then the type of the variable will be number. Likewise we can assign string, object, and array.
JavaScript variables has standardised naming conventions while declaring the variables:
- Don’t use the JavaScript language keywords such as If, for, else-if, true, false, while, function etc.
- Do not start with a digit 0, 1, 2,…9.
- Do not use special characters (%, S, &) inside the name.
- Start with an alphabet or followed by an alphabet or digits or underscore.
- Can use uppercase or lowercase alphabets.
Valid Variable Names with Examples:
- var Sum;
- var first_name;
- var testCase_1;
Invalid Variable Names with Examples:
- var 1st_sum;
- var function;
- var last$name;