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

Why null? #29

Open
sindresorhus opened this issue Aug 21, 2024 · 5 comments
Open

Why null? #29

sindresorhus opened this issue Aug 21, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@sindresorhus
Copy link

I personally think it should be undefined, but either choice should be defended in the proposal.

@arthurfiorette
Copy link
Owner

All of your points makes a lot of sense. Will change to the next proposal rewrite as well defend the usage of undefined.

I guess

  • typeof null === 'object'
  • default parameters only work with undefined

are both very strong arguments in favor of undefined.

@arthurfiorette arthurfiorette added the enhancement New feature or request label Aug 21, 2024
@felippe-regazio
Copy link

Maybe could be helpfull to say that null has a "synthetic use". The JS compiler/interpreter/engine will always assign undefined to indicate the absense of a value.

@bmeck
Copy link

bmeck commented Aug 22, 2024

This actually is a difference in JS vs WHATWG specs commonly brought up. JS specifications should return undefined while DOM generally prefers null.

@felippe-regazio
Copy link

felippe-regazio commented Aug 22, 2024

This actually is a difference in JS vs WHATWG specs commonly brought up. JS specifications should return undefined while DOM generally prefers null.

I see. But we cannot merge SPECs. The DOM is not part of the JavaScript SPEC, but is instead a Web API with follows another SPEC (https://www.w3.org/TR/1998/WD-DOM-19980416/). Since this proposal is being opened to JS I'm proposing to follow the specification guidelines. Per SPEC JS defines null as "primitive value that represents the intentional absence of any object value" (https://tc39.es/ecma262/#sec-null-value). Since we are talking about "safe check" for unintentional behavior, my point its that "undefined" may fit better.

@ishank-s
Copy link

++ we should just nuke null from javascript.
It doesn't get caught in default variables in params.It's typeof null === 'object'. It's such a footgun

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

No branches or pull requests

5 participants