1. Home
  2. Computing & Technology
  3. JavaScript

undefined

By Stephen Chapman, About.com

Definition: undefined is a global property (variable) with a constant value. Javascript treats undefined as being equal to null. A variable that has not been defined at all or which has been defined but not yet given a value will be considered to have a value of null or undefined. Some of the Javascript documentation states that a field that is not declared is null while one that is declared but has no value is undefined. Logically I would have assumed a field that has not been declared is undefined while one that is declared but without a value is null - the exact opposite of what the documentation says. As the two values are considered to be equal which means what is a moot point. The one difference between null and undefined is that null is a reserved word while undefined is not. As undefined is not a reserved word so you can declare your own variable or function called undefined but if you do then you will not be able to test if a field is undefined (although you will still be able to test if it is null).
Examples: if (x == undefined)

Explore JavaScript

More from About.com

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Reference
  5. Javascript Glossary - undefined

©2008 About.com, a part of The New York Times Company.

All rights reserved.