JavaScript is different from other programming languages by containin both undefined and null values, which may cause confusion.

null is a special value meaning "no value". null is a special object because typeof null returns 'object'.

On the other hand, undefined means that the variable has not been declared, or has not been given a value.

Following snippets display 'undefined':

// i is not declared anywhere in code
alert(typeof i);

var i;
alert(typeof i);

Although null and undefined are slightly different, the == (equality) operator considers them equal, but the === (identity) operator doesn't.

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!

Currently rated 5.0 by 6 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories : All | JavaScript | Tips
Share & Support : del.icio.us | DZone it! | Kick it! | digg it! | Furl | Technorati


June 20. 2008 11:36

Interesting article. Succinct.


Simon | Reply

October 21. 2009 16:32

Social comments and analytics for this post

This post was mentioned on Twitter by yansern: #Javascript null is an object. undefined means undeclared variable. == considers them equal, === considers them not.  http://im.ly/2e6b8/

uberVU - social comments | Reply

October 27. 2009 14:26

Do you make money out of this blog? just curious

cash loans | Reply

November 4. 2009 20:17

Interesting stuff you've go here

PaydayLoans | Reply

Add comment

(Will not be displayed!)