JavaScript Identifiers Variables And Constants
Identifiers, Variables and Constants
Identifier
To model the real-world entities, we will need to name them to use them in the JavaScript program.
Identifiers are these names that help us in the naming of elements in JavaScript.
For example :
CODE/PROGRAM/EXAMPLE
tempFahrenheit;
tempCelsius;
Identifiers should follow below rules:
- The first character of an identifier should be letters of the alphabet or an underscore (_) or dollar sign ($).
- Subsequent characters can be letters of alphabets or digits or underscores (_) or a dollar sign ($)
- Identifiers are case-sensitive. Hence, tempCelsius and TempCelsius are not the same
Reserved keywords are part of programming language syntax and cannot be used as identifiers.
Variables and Constants
For temperature conversion app, in case of fever, temperature value will vary whereas the value for normal body temperature will always be the same.
The identifiers that we choose to hold data which varies is called as Variables
The identifier that we choose to hold data which does not vary is called Constant.
To declare a variable, we optionally use the 'var' keyword. The value for the same can be initialized optionally. Once the value is initialized, it can be modified any number of times in the program.
To declare a constant we use 'const' keyword followed by an identifier. The value is initialized during declaration itself and cannot be altered later.
Value or literal is the data related to the real-world entity.
Values can be of different types like number, string, boolean, etc.
Example
number : It can be a floating-point and can be written with/without the decimal point
30020.5010001
string : It is a text written within single quotes ‘ ’ or double quotes “ ”
"India""Australia"‘Jasmine’
boolean : There are 2 boolean values
truefalse