[JS] Null or undefined in prototype chain
Hey I read that if we search beyond the prototypes linked together i.e. the chain ends and we are still searching we get null.
Also, if the function or property is not found, we get undefined.
Now, how is it possible to get undefined, if I will end up searching beyond the chain, wouldn't I always get null? The reason, I will end up searching beyond the chain is coz that function or property doesn't exist, so we wont give up and keep on searching. Which means it is impossible to get undefined?
2 Replies
the only way i can think of of getting to the end of the chain is by creating an object with
null
prototype
it's not that it doesn't have a prototype: everything MUST havve a prototype
it's just that the prototype is null
the prototype ALWAYS existsalso, keep this in mind: it can't be set to
undefined
either