Udostępnij za pośrednictwem


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

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

Version 5.5

Applies To:

Global Object

See Also

Concepts

Undefined Values