Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  14] [ 2]  / answers: 1 / hits: 115653  / 13 Years ago, tue, june 21, 2011, 12:00:00

I am really confused as to when JavaScript returns null or undefined. Also different browsers seem to be returning these differently.



Could you please give some examples of null/undefined with the browsers that return them.



While I am now clear on the undefined aspect, I am still not 100% clear on null. Is it similar to a blank value?



E.g. You have a text box which does not have any value set. Now when you try to access its value, will it be null or undefined and are they similar?


More From » null

 Answers
31

The DOM methods getElementById(), nextSibling(), childNodes[n], parentNode() and so on return null (defined but having no value) when the call does not return a node object.



The property is defined, but the object it refers to does not exist.



This is one of the few times you may not want to test for equality-



if(x!==undefined) will be true for a null value



but if(x!= undefined) will be true (only) for values that are not either undefined or null.


[#91583] Monday, June 20, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bryonk

Total Points: 161
Total Questions: 116
Total Answers: 107

Location: Albania
Member since Sun, Nov 22, 2020
4 Years ago
bryonk questions
;