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

Number.NaN and reserved word #286

Closed
kkapsner opened this issue Oct 5, 2011 · 3 comments
Closed

Number.NaN and reserved word #286

kkapsner opened this issue Oct 5, 2011 · 3 comments
Milestone

Comments

@kkapsner
Copy link

kkapsner commented Oct 5, 2011

If I use Number.NaN (which is perfectly valid) I get

Expected an identifier and instead saw 'NaN' (a reserved word).

First: NaN is NOT a reserved word - it is a global Variable that should not be overwritten (and JSHint should warn you if you do it).
Second: Number.NaN is part of the ES-spec (in 3 and 5)

PS: in ES3 are some FutureReservedWords (like "boolean") which are not recognised in JSHint. If I write

var obj = {boolean: true};

I get no warning form JSHint although it's invalid ES3 (not ES5), because in ES3 an identifier cannot be a reserved word.
In fact I know no Browser who claims about this (I only checked "boolean") - but just for consistency.

@WolfgangKluge
Copy link
Contributor

Yes, it's a bug. But can you give me an example where you use Number.NaN.
As I understand, you can only use it for assignments, not for tests (that's what isNan is for). Right?

var x = Number.NaN;
if (isNaN(x)) {
    x = 2;
}

Reserved keywords.
The future reserved keywords in ES3 are

abstract enum int short
boolean export interface static
byte extends long super
char final native synchronized
class float package throws
const goto private transient
debugger implements protected volatile
double import public

In ES5 the list ist somewhat shorter

class enum extends super 
const export import

when in strict-mode, the following are future-reserved, too:

implements let private public yield
interface package protected static

I think, jshint should warn if I use one of them, too - even if they are defined in ES3 or if the parser is not in strict-mode.

@kkapsner
Copy link
Author

kkapsner commented Oct 6, 2011

Yes, I use Number.NaN for an assignment (if any numeric property can not be destiguished I assign Number.NaN - I could also just use NaN... BUT in older Browser it may be overwritten by a different script) and you can not use it for testing because

(NaN === NaN) === false

only value in JS that is not equal to it self.

@kkapsner
Copy link
Author

The "boolean"-issue is still open...

jugglinmike pushed a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014
NaN is not a reserved word according to the ES5 spec and treating it
like one prohibits the use of (equally valid) Number.NaN.

Relevant:

  * List of ES5 reserved words: http://es5.github.com/#x7.6.1
  * Closes jshintGH-286
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