Suppose I have some variables:
var s = 's', i = 0, o = {}, a = [], n = null, nan = NaN, u;
How can I make any sense of when reading x.p
will return undefined, and when it will throw a TypeError
?
s.p; // undefined
i.p; // undefined
o.p; // undefined
a.p; // undefined
n.p; // TypeError!
nan.p; // undefined
u.p; // TypeError!
P.S. Are null
and undefined
the only weird values in this way? Are there others?
Edit
I'm aware that by declaring variables as I have, several of my values have been automatically wrapped by objects (e.g. Number
), despite being primitives. Therefore I can treat them like "proper" objects (e.g. {}
, []
) and attempt to read their properties. But I can't find much explaining what is and isn't wrapped this way.