Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ECMA script offer no integer type out of the box?

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?

like image 784
Udo Klein Avatar asked Aug 03 '15 05:08

Udo Klein


People also ask

What does ECMAScript do?

ECMAScript (/ˈɛkməskrɪpt/; ES) is a JavaScript standard intended to ensure the interoperability of web pages across different browsers. It is standardized by Ecma International in the document ECMA-262.

Is JavaScript ECMAScript?

JavaScript is a general-purpose scripting language that conforms to the ECMAScript specification. The ECMAScript specification is a blueprint for creating a scripting language. JavaScript is an implementation of that blueprint. On the whole, JavaScript implements the ECMAScript specification as described in ECMA-262.

What is ECMA stand for?

Ecma International (formally European Computer Manufacturers Association) is a non-profit organization that develops standards in computer hardware, communications, and programming languages.

In what year does ECMA released the standard calling the language ECMAScript?

The development of this Standard started in November 1996. The first edition of this Ecma Standard was adopted by the Ecma General Assembly of June 1997.


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. :)

like image 157
Kit Sunde Avatar answered Oct 11 '22 20:10

Kit Sunde


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

like image 41
MinusFour Avatar answered Oct 11 '22 21:10

MinusFour