Why is "float" a reserved word in JavaScript?
Asked Answered
S

1

6

I just found myself writting a variable called float and Sublime Text made it blue, like it would with "document" or "window". Then I tried to write that in Chrome's console and see what it was... but it seems like, at least, it is not a global variable.

What is float in Javascript and why is it a reserved word? May it be for a possible future use?

EDIT: For those downvoting: I found it actually is a reserved word here: http://www.w3schools.com/js/js_reserved.asp

EDIT2: As ES6 is adding real classes to JS, and it seems JS is looking more and more like Java, could it be possible that in the future you'd have to define a variable as Float my_number = 1.1234; ?

Sandberg answered 10/9, 2015 at 10:36 Comment(6)
Why is “float” a reserved word in JavaScript? - it's not. Probably some incorrect highlighting rules in your sublimeApartheid
@Apartheid developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… actually it is..Mascagni
Well, OK. It was. Because now ES5 is everywhere and ES2015 is ongoing.Apartheid
@jycr753 Future reserved keywords in older standards The following are reserved as future keywords by older ECMAScript specifications (ECMAScript 1 till 3).Depreciable
@Apartheid well it was. but I guess they still hight light it for the same reason a lot people still uses IE 8Mascagni
For those downvoting: this actually is a legit question, with a simple answer. No need to downvote.Osher
O
12

Float is NOT reserved in the current ECMAScript (4-5) or in the upcoming version (6), but was in previous specificiations.

The official reason:

Future reserved keywords in older standards

The following are reserved as future keywords by older ECMAScript specifications (ECMAScript 1 till 3).

abstract - boolean - byte - char - double - final - float - goto - int - long - native - short - synchronized - transient - volatile

Additionally, the literals null, true, and false are reserved in ECMAScript for their normal uses.

The entire information can be read here

For those who still don't believe me the float in this jsFiddle is a lie

var float = "definitively not a float";
Osher answered 10/9, 2015 at 10:40 Comment(4)
Is it any different in ES6, as specified on my edition?Sandberg
Just updated my answer: no, the upcoming version doesn't reserve float either.Osher
@Sandberg and updated once again to prove it as well. :)Osher
Netbeans minifier will not minify a js file which uses float - treating it as a reserved word.Dioptrics

© 2022 - 2024 — McMap. All rights reserved.