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);
alert(typeof i);
var i;
alert(typeof i);
alert(typeof i);
Although null and undefined are slightly different, the == (equality) operator considers them equal, but the === (identity) operator doesn't.






No comments:
Post a Comment