undefined
global variableS2C Home « Globals « undefined
The JavaScript global variable undefined
can be used to determine if assignment has taken place and is returned from methods and functions when no value is available.
- Variables that are not initialized have a type of
undefined
. - Uninitialized variables evaluated in methods and statements return
undefined
. - Functions with no return value return
undefined
.
Examples
The code below just creates a variable without a value.
// Create an uninitialised variable and display it.
var undefinedVariable;
alert(undefinedVariable);
// Create three undefined variables.
var dVariable, eVariable, fVariable;
alert(dVariable + ' ' + eVariable + ' ' + fVariable);
Related Tutorials
JavaScript Basic Tutorials - Lesson 6 - Variables