Every application ever written, regardless of the programming language, has used variables of some sort, and ASP scripts are no exception. Both VBScript and JScript allow you to create and manage variables simply and easily.
Each language deals with variable declaration differently. Both JScript and VBScript are quite flexible about variables and their declaration. In VBScript, any variable is automatically considered to be of the Variant type when it is initially declared with the Dim statement. Each variable eventually is assigned a subtype, such as Numeric and Array. JScript is similar; the variable is initially declared with the var statement. Both languages, in general, try to perform much of the data type management, including type conversion, automatically. In fact, you don't even have to use the Dim or var statements at all to use a new variable; they are optional in their respective languages.
This sample declares several different kinds of variables, performs simple operations on them, and then displays them to the client browser using the special <% = ...%> script delimiters. An integer is assigned to the variable intVariable, added to itself, and the sum sent to the client browser. StrVariable is set to equal to the first name, is added to Smith, and sent to the client browser. Booleans and dates are likewise declared or created, initialized, manipulated, and displayed.
Of particular interest is the final step in the date variable demonstration. In VBScript, the variable is first assigned a literal date string, and displayed. It is then reset, and assigned the value that is returned by the VBScript Now function, which returns the current system time. The JScript example uses the JScript Date function to set both the initial literal by passing parameters to the function, and then to set the variable equal to the current system time by passing no parameters to the function.
The VBScript and JScript versions of this script are available in the IIS samples directory, at ...\asp\simple\Variables_VBScript.asp and ...\asp\simple\Variables_JScript.asp.