I am wondering why ECMA script does not support integers out of the box. Of course I know that there are some kind of integers (there is a good summary in the answer to this question: Difference between floats and ints in Javascript?). But still these are not "real" integers. And the problems with floats as ints are pretty abundant. So why does it not support integers and why was this not fixed with ECMA script 6?
-
Since there are no explicit type declarations for a number (and thus no way to express a difference between an int and a float), life is a lot less complicated if there aren't multiple types of numbers that could result from any given operation. – jfriend00 Aug 03 '15 at 06:05
-
2TypedArrays are quite real. What are you looking for? – Amit Aug 03 '15 at 06:21
-
I was trying to understand why it is the way it is and if there is any hope that will eventually be fixed. With regard to the simplicity: IMHO this is an ex post justification. I completely understand that you can not do much better if you have to coble out a languange in 10 days. – Udo Klein Aug 04 '15 at 04:51
2 Answers
The language was designed and implemented in 10 days, so it was originally a matter of time constraints. From the horses mouth:
Yes, it was there from the start. But bignums were not in the cards. JS had to "look like Java" only less so, be Java's dumb kid brother or boy-hostage sidekick. Plus, I had to be done in ten days or something worse than JS would have happened.
So double by default, int under the hood, and bitwise ops are 32-bit int (uint if you use >>>). I blame Java.
I wouldn't know why it wasn't on the table for ES2015. To me it seems like a lot of the work as to remove boilerplate, but I'd be guessing. Brendan Eich is pretty active on Twitter, you could probably just ask him. :)
-
2I think the political infighting which killed ES4 - particularly IBM's childlike but successful attempt to bomb the whole process unless `IEEE 754r DEC128` was included dissuaded TC39 from mucking about with any of the number types in Harmony. Just a theory though. https://www.youtube.com/watch?v=V1_Y-KVhZ9Q&t=14m – max Aug 03 '15 at 06:24
-
@KitSunde: I'll remove my comment, since the other answer conveys what I'm thinking of nicely. – nhahtdh Aug 03 '15 at 07:18
-
4It *was* on the table for ES2015. You're right that it's a lot of work to get this a) right and b) backwards-compatible, and therefore proposals introducing (custom) new types were postponed to ES2016. – Bergi Aug 03 '15 at 14:36
-
Understood. Every year it will get slightly harder with regard to compatibility. Hopefully this gets fixed soon. – Udo Klein Aug 04 '15 at 04:52
Can't really speak for Harmony, Douglas Crockford, said that they were interested in adding another number type in future editions of ES. However, he also said that adding a new number type was doing violence to the language, that the simplicity of the language was desirable.
https://www.youtube.com/watch?v=V1_Y-KVhZ9Q
He basically starts talking about "Number" from 13:52 to 26:00

- 13,913
- 3
- 30
- 39