In any programming language, data represents information. For example, this string literal contains a question:
'How old am I?'
Variables and constants store data that scripts can easily reference by using the name of the variable or constant. Data stored by a variable may change as a program runs, while data stored by a constant cannot change. A script that uses a variable actually accesses the data that the variable represents. Here is an example in which the variable named
NumberOfDaysLeft is assigned the value derived from the difference between
NumberOfDaysLeft = EndDate вЂ“ TodaysDate;
In a mechanical sense, a script uses variables to store, retrieve, and manipulate the values that appear in scripts. Constants reference data that that does not change. Always create a meaningful variable name to help you remember the variable's purpose and to help others determine the script's functionality.
In This Section
- Types of JScript Variables and Constants
Discusses how to choose an appropriate data type for a variable and the benefits of proper variable data type selection.
- Declaring JScript Variables and Constants
Explains how to declare typed and untyped variables and constants and how to initialize them.
- Scope of Variables and Constants
Illustrates the difference between global and local scopes in JScript and how the local scope shadows the global scope.
- Undefined Values
Explains the concept of undefined values, how to determine if a variable or property is undefined, and how to undefine variables and properties.