Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeof null is object, not 'null' #1933

Closed
kahnvex opened this issue Dec 15, 2014 · 7 comments
Closed

typeof null is object, not 'null' #1933

kahnvex opened this issue Dec 15, 2014 · 7 comments

Comments

@kahnvex
Copy link

kahnvex commented Dec 15, 2014

This seems odd to me. jQuery thinks null references are type "null" (string null). But javascript's typeof thinks null references are type object.

>typeof null
'object'

Why does jQuery treat null as its own type? Treating it's "type" as an object is useful in certain cases, and since that is what the language does, this seems odd.

@scottgonzalez
Copy link
Member

If typeof provided values we wanted, then jQuery.type() wouldn't exist. Please read the docs.

@kahnvex
Copy link
Author

kahnvex commented Dec 15, 2014

Seems odd that jQuery makes up its own types, but ok.

@rwaldron
Copy link
Member

It's not "odd" because jQuery isn't making up it's own types: http://es5.github.io/#x8.2

typeof null === "object" began as a bug in the first implementation of JavaScript and then it stuck:

0x0 === 0, hence erroneous typeof result.

@timmywil
Copy link
Member

Ok, I kind of knew this, but Rick just blew my mind.

@rwaldron
Copy link
Member

@timmywil 😉

I just realized that I shouldn't have used === since I was talking about C code, haha

@dcherman
Copy link
Contributor

@rwaldron That's pretty interesting! Out of curiosity, if this was a bug, I would have thought that there would be an ( accidentally ) unused definition for JSVAL_NULL or another condition in JS_TypeOfValue, but that may be due to my gross inexperience with C.

@rwaldron
Copy link
Member

I think it was the logical connection of NULL pointer to null :)

Sometimes bugs, right?

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

5 participants