Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
111
rated 0 times [  115] [ 4]  / answers: 1 / hits: 17286  / 6 Years ago, sun, may 13, 2018, 12:00:00

What is the difference between Null, NaN and undefined in JavaScript?



I have come across all three values, and have understood them to be “there isn’t anything here” in the context I found them- but I was hoping for a more detailed explanation as to why they occur, as well as what they mean in different contexts (for example- against an array, vs a class or variable).


More From » javascript

 Answers
58

NaN: Not a number: As the name implies, it is used to denote that the value of an object is not a number. There are many ways that you can generate this error, one being invalid math opertaions such as 0/0 or sqrt(-1)



undefined: It means that the object doesn't have any value, therefore undefined. This occurs when you create a variable and don't assign a value to it.



null: It means that the object is empty and isn't pointing to any memory address.


[#54439] Thursday, May 10, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kamryn

Total Points: 645
Total Questions: 100
Total Answers: 118

Location: Tanzania
Member since Wed, Feb 24, 2021
3 Years ago
;