Difference between Null and Undefined
1. By default when you declare a variable and not assign any value to it, it would be undefined.
2. Null is basically a object which you can set to a variable, same like other languages, you can assign null to variable to
set it's value to nothing.
3. typeOf(undefined) is undefined while typeOf(null) is object.
4. when you will perform any arithmetic operation on 'undefined' you will get following result :
var a;
a+'string' = 'undefinedstring' (result)
a+5=NaN
a+true=NaN
a+null=NaN
while if you will perform arithmentic operation with Null then you will get following result
var a=null;
a+'string'='nullstring'
a+5=5
a+true=true
1. By default when you declare a variable and not assign any value to it, it would be undefined.
2. Null is basically a object which you can set to a variable, same like other languages, you can assign null to variable to
set it's value to nothing.
3. typeOf(undefined) is undefined while typeOf(null) is object.
4. when you will perform any arithmetic operation on 'undefined' you will get following result :
var a;
a+'string' = 'undefinedstring' (result)
a+5=NaN
a+true=NaN
a+null=NaN
while if you will perform arithmentic operation with Null then you will get following result
var a=null;
a+'string'='nullstring'
a+5=5
a+true=true
No comments:
Post a Comment