difference between null and undefined

webMahesh

Power Member
Jr. VIP
Joined
Sep 8, 2022
Messages
502
Reaction score
82
Can anyone explain the difference between null and undefined in JavaScript.
 
Null is set by you. Undefined is unknown, unset.

There are cases in which you want something empty. That's null.
 
You can literally make a quick google search or ask ChatGPT for the anwser,
Don't bother yourself/others with each mini question,
Just a small advice, it will buy you/us plenty of time
 
They are different things. Null is a value and it is a primitive. Undefined is not a value. Whenever you see undefined for a variable, it means that the memory has been assigned for that var, but it doesn’t have a value assigned to it.
 
In addition to everything that was said before, when you are trying to use typeof null it will give you object, it`s because of old legacy bug, which is kept until this days, and typeof undefined will give you more obvious undefined. Also type casting will convert null and undefined, so == comparison will give you true between them, but not ===
 
null represents an intentional absence of value, while undefined indicates a variable has been declared but not assigned.
 
Back
Top