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

Some values (like undefined) should have a reserved keywords (like null) #25

Open
DavidBruant opened this issue May 2, 2013 · 8 comments

Comments

@DavidBruant
Copy link
Owner

Some names (like undefined and NaN) can be used as identifiers making it hard to use them 100% reliably as values (which is what people expect naturally). This leads people to write things like typeof x === "undefined" while they could just be writing x === undefined, or use void 0 etc.

List of things that shouldn't be allowed as identifiers:

  • undefined
  • NaN
  • Infinity
@michaelficarra
Copy link

It's pretty much become taboo to use the identifier undefined or use the word "undefined" in a sentence without qualifying it. In my ECMAScript Glossary, I discourage its use and instead ask people to use the terms "undeclared" or "undefined value" depending on what they mean. Other possible uses are "an identifier named undefined" or "the undefined property of the global object".

But I don't think a keyword would have been the ideal solution. It should have been omitted entirely. What other language has two absence representations?

@ghost
Copy link

ghost commented May 2, 2013

But I don't think a keyword would have been the ideal solution. It should have been omitted entirely. What other language has two absence representations?

Agreed—to date, the best (though, IMO, not fully correct) distinction I've seen between undefined and null is that the former represents an unspecified value, while the latter is explicitly omitted. But that seems like retrospective justification for an odd design decision.

@DavidBruant
Copy link
Owner Author

Fair enough. I created issue #26 and I'm repurposing this issue from:
undefined should be a reserved keyword (like null) to
undefined and NaN should reserved keywords (like null)

@michaelficarra
Copy link

@DavidBruant: Are you forgetting about Infinity?

@DavidBruant
Copy link
Owner Author

I totally am. Making the title more general and keeping the list up-to-date in the description. Thanks!

@vendethiel
Copy link

Has anobody ever been in a situation were undefined or NaN were redefined ? I think people deserve what they're gonna get if they do that. I don't usually check with typeof, I just don't see the point in doing that.

@DavidBruant
Copy link
Owner Author

Has anobody ever been in a situation were undefined or NaN were redefined ? I think people deserve what they're gonna get if they do that. I don't usually check with typeof, I just don't see the point in doing that.

I agree with you but that's not the point here. The idea of ECMAScript Regrets is to list all the things the language got wrong and can't be fixed because some content on the web may relies on the particular behavior. The idea is to educate JS devs and hopefully help compile-to-JS language designers.

Per ES5, it is not possible to redefine them, but it's possible to use them as identifiers (variable names, function arguments...). There is no good reason to do that, so there is no reason for the language to allow that (hence being a "regret")

@vendethiel
Copy link

Fair enough; I agree :).

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

3 participants