Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In JavaScript, every number you will ever use will always be represented with what C programmer would call a double. The official type is I believe number. If I recall correctly, that fact was mentioned by Google as a "fundamental" problem with JavaScript and one of the reason why they wanted to have clean break with Dart. Now, I can't help but wonder :

  • Can the ECMAScript standard just add that type? Would it be possible to do without breaking existing code?
  • Anyway, can't a JIT engine watch the integer usage and generate code that is almost as efficient as using a native integer type, by using integer registers and opcodes?

In effect : Could it be done? Why should it be done?

share|improve this question
Javascript 2.0 has that, and more. Hopefully we can get support in modern browsers in the next few years. – Robert Harvey Jul 15 '13 at 4:26
Question: what does 9999999999999999 % 9 evaluate to? ;) – Hubert OG Jul 15 '13 at 21:47

As for your second point, yes, integer use can be detected. Firefox does it as part of their asm.js feature. It's not entirely straightforward: for example, adding two integers may overflow. That wont happen if the values were added as double. To account for this, every expression that should produce a true 32 bit int is appended with | 0, which does nothing except forcing the result to be an int.

share|improve this answer
I see. Could it be done non asm.js code though? – Laurent Bourgault-Roy Jul 16 '13 at 15:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.