Thursday, 9 January 2020

Javascript : Difference between undefined and null

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

No comments:

Post a Comment

JQuery : Quick Review

JQuery Selectors :selectors allows us to find a html elements so, we can manipulate it's attributes programmatically.  Id Sele...