Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

undefined Property

Returns the value of undefined.

undefined

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.

NoteNote

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.

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.