undefined Property
Returns the value of undefined.
undefined
Remarks
The undefined property is a member of the Global object, and becomes available when the scripting engine is initialized. When a variable has been declared but not initialized, its value is undefined.
If a variable has not been declared, you cannot compare it to undefined, but you can compare the type of the variable to the string "undefined".
The undefined property is useful when explicitly testing or setting a variable to undefined.
Note
To compile a program that uses an undeclared variable from the command line, you must turn off the fast option by using /fast-. Undeclared variables cannot be used when a program is running in fast mode. It is not safe to turn off the fast option in ASP.NET because of threading issues.
Example
The following example illustrates the use of the undefined property:
var declared;
if (declared == undefined)
print ("declared has not been given a value");
else
print ("declared has been given a value");
print ("typeof declared is " + typeof(declared));
// An undeclared variable cannot be compared to undefined,
// so the next line would generate an error.
// if (notDeclared == undefined) ;
print ("typeof notDeclared is " + typeof(notDeclared));
The output of this code is as follows.
declared has not been given a value
typeof declared is undefined
typeof notDeclared is undefined
Requirements
Applies To:
See Also
Concepts
Change History
Date |
History |
Reason |
---|---|---|
July 2009 |
Modified example. |
Content bug fix. |
July 2009 |
Modified note about /fast mode. |
Content bug fix. |
March 2009 |
Modified example. |
Information enhancement. |