The Undefined Type
The Undefined type has only one value, undefined. When a variable is declared without initialization, it is assigned the value of undefined:
<!DOCTYPE html>
<html>
<head>
<title>Undefined Example</title>
<script type="text/javascript">
var aString;
document.writeln(aString == undefined); //true
</script>
</head>
<body>
</body>
</html>
We can explicitly assign undefined to a variable.
<!DOCTYPE html>
<html>
<head>
<title>Undefined Example</title>
<script type="text/javascript">
var aString = undefined;
document.writeln(aString == undefined); //true
</script>
</head>
<body>
</body>
</html>
A variable containing undefined value is different from an undefined variable.
<!DOCTYPE html>
<html>
<head>
<title>Undefined Example</title>
<script type="text/javascript">
var aString;
document.writeln(aString); //"undefined"
document.writeln(anotherValue); //causes an error
</script>
</head>
<body>
</body>
</html>
Home
JavaScript Book
Language Basics
JavaScript Book
Language Basics
Data Types:
- JavaScript Data Types
- typeof Operator
- The Undefined Type
- null Type
- null vs undefined
- Boolean Type
- Boolean() casting function
- The Literials of Number Type
- Octal Integer
- Hexadecimal
- Floating-Point Values
- Value range
- NaN
- Number Conversions:Number(), parseInt() and parseFloat()
- Number() function
- parseInt()
- parseFloat()
- The String Type
- String Literals and Escapes
- Get the String Length
- Converting to a String with toString() method
- Convert Number to String with radix
- Convert to String with String() casting function