The basic difference is that
undefined and null represent different concepts.
If only
null was available, you would not be able to determine whether null was set intentionally as the value or whether the value has not been set yet unless you used cumbersome error catching: eg
However, if you intentionally set the value to
null, strict equality with undefined fails, thereby allowing you to differentiate between null and undefined values:
basically if we just declare a variable in js its type is undefined
var b; console.log(typeof b);// must print undefined but if we declare a object and initialize with null its type is 'object' not undefined var b = null; console.log(typeof b) // must print object not undefined. |
Thursday, September 15, 2016
why undefined and null coexist in java script(Node js).
Subscribe to:
Posts (Atom)