JavaScriptProgrammer'sReference

Integer promotion is a concept that is used in compilers where there are many more strongly enforced data typing rules.

All the same, JavaScript does the same thing automatically without you realizing it.

The process of promoting a value is to convert it to a higher resolution data type, so that an expression can be evaluated in that higher data type's context without any loss of value.

For example, adding a floating point and an integer value together would be promoted to a floating-point addition. The result would stay as a floating point value. However it is conceivable that adding an integer and two floating points together might yield a result that had a zero value fractional part. That resulting value could then be demoted safely back to an integer with no loss of value.

That would be a value preserving demotion.

Most current implementations of JavaScript do not do a great deal of internal promotion and demotion other than conversions between numeric values and strings. This is because the language is currently a weakly typed language and is somewhat forgiving in the area of data types.

Many reserved words are specified by the ECMA standard. There is a comment in the standard that allows implementations to support these reserved words. This suggests that sometime in the future the standard may allow for more strongly typed data vales. Indeed, some implementations may already provide that functionality and still be ECMAScript compliant.

At such a time that an implementation does more strongly type its data values, then this integer promotion may be more visible.