Undefined Values

In JavaScript, a variable without a value, has the value undefined. The typeof is also undefined.
  var person;  <=== Value is undefined, type is undefined

Any variable that has been defined can be emptied, by setting the value to undefined. This will also makes the type undefined.
  var person1 = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};<=== Value is defined, type is object data type
  person1 = undefined;  <=== Value is now undefined, type is undefined as well

HTML file: Displayed by browser:
<body>
<h3>Using var person;:</h3>
<p>Both the value, and the data type, of a variable with no value is <b>undefined</b>.</p>
<p id="person">person</p>
<hr />
<h3>Using person1 = undefined;:</h3>
<p>Variables can be emptied by setting the value to <b>undefined</b>.</p>
<p id="person1">person1</p>
<script>
   var person;
   document.getElementById("person").innerHTML
   = person + "<br />" + typeof person;
   var person1 = {firstName:"John",
   lastName:"Doe", age:50, eyeColor:"blue"};
   var person1 = undefined;
   document.getElementById("person1").innerHTML =
   person1 + "<br />" + typeof person1;
</script>
</body>

Using var person;

Both the value, and the data type, of a variable with no value is undefined.

person


Using person1 = undefined;

Variables can be emptied by setting the value to undefined.

person1

BackTable of ContentsNext