JavaScript Integer Maximum and Minimum Values Are Defined by Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER
In JavaScript, the maximum and minimum integer values can be obtained with Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER respectively.
I needed to define the minimum integer value in a JSON file, and thought “What was JavaScript’s minimum integer value again?” so I researched it.
JavaScript’s maximum integer value is defined by the constant Number.MAX_SAFE_INTEGER, and its value is 9007199254740991.
JavaScript’s minimum integer value is defined by the constant Number.MIN_SAFE_INTEGER, and its value is -9007199254740991.
It seems that JavaScript integer precision is maintained up to 2^53, not 2^64.This appears to be because JavaScript has no integer type and everything is represented as floating-point type. JavaScript’s floating-point type is thought to conform to IEEE 754. (「Javascript の整数の精度が保たれるのは2の64乗ではなく、2の53乗までらしい。これは、JavaScript には、整数型がなく全て浮動小数点型で表現されるためのようです。JavaScript の浮動小数点型はIEEE 754 に準拠していると思われます。」)
That’s all from the Gemba where I want to safely handle maximum and minimum integer values in JavaScript.