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

Answer to quesion 14 is wrong (well, right multi-choice answer, but wrong explanation) #775

Open
jonrandy opened this issue Mar 17, 2024 · 3 comments

Comments

@jonrandy
Copy link

You say:

All objects have prototypes, except for the base object.

This is incorrect. It's trivial to create an object without a prototype...

const objectWithNoPrototype = Object.create(null)
@LeszekSwirski
Copy link

Interesting question of semantics - I'd argue that it's wrong, because your example does have a prototype, and that prototype is the null value (after all, typeof null is "object").

@jonrandy
Copy link
Author

jonrandy commented May 17, 2024

But then, wouldn't the original also be wrong because the prototype of the base object is null too? 'All objects have prototypes, except for the base object.' suggests it doesn't have one (or that having null as a prototype is equivalent to not having one).

From MDN - "The prototype of Object.prototype is null, so it's at the end of the prototype chain"

So, based on the phrasing of the initial statement it is suggested that objects must have a prototype, and cannot be like the base object which 'does not have one'... which is not correct.

But yeah, semantics play into this a lot.

@LeszekSwirski
Copy link

Yeah I don't consider the original explanation to be correct either. It kind of depends on what you consider to be an "object" - is null an object, since it has typeof "object"? Or are we saying "object" is any non-primitive? If it's the former, then "false" is correct, with "null" being the counter example. Otherwise, "true" would be correct, because every non-primitive has a prototype (but that prototype can be a primitive, so there doesn't have to be an infinite depth prototype chain - but there can be!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants