Partager via


undefined Property (Windows Scripting - JScript)

 

Returns an initial value of undefined.

Syntax

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.

The following example illustrates the use of the undefined property.

var newline = "<br />";
var s = "";

var declared;
if (declared == undefined)
    s += "declared has not been given a value";
else
    s += "declared has been given a value";
    
s += newline;
s += "typeof declared is " + typeof(declared);

// An undeclared variable cannot be compared to undefined,
// so the next line would generate an error.
// if (notDeclared == undefined) ;

s += newline;
s += "typeof notDeclared is " + typeof(notDeclared);

document.write(s);

// Output:
// declared has not been given a value
// typeof declared is undefined
// typeof notDeclared is undefined

Requirements

Version 5.5

Applies To: Global Object (Windows Scripting - JScript)

Change History

Date

History

Reason

March 2009

Modified example.

Information enhancement.

See Also

typeof Operator (Windows Scripting - JScript)