It's kinda hard to believe -- but I can't find info about the largest possible integer allowed in node.js, in either Google or SO. There are plenty of articles on the largest integer in browser Javascript, but I just wonder things could be different in node.js.
Can anyone give some pointer? Thanks!
It's kinda hard to believe -- but I can't find info about the largest possible integer allowed in node.js, in either Google or SO. There are plenty of articles on the largest integer in browser Javascript, but I just wonder things could be different in node.js.
Can anyone give some pointer? Thanks!
Share Improve this question asked Nov 22, 2016 at 10:57 lgc_ustclgc_ustc 1,6642 gold badges21 silver badges32 bronze badges 5-
2
Number.MAX_SAFE_INTEGER
- just like all javascript engines – Jaromanda X Commented Nov 22, 2016 at 10:59 - 2 Define "largest integer." – T.J. Crowder Commented Nov 22, 2016 at 10:59
-
2
Try running
console.log(Number.MAX_SAFE_INTEGER)
. NodeJS is fancy, but at its heart it's still just JavaScript. – Emil S. Jørgensen Commented Nov 22, 2016 at 10:59 - You can find the response right there : developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – I'm_ADR Commented Nov 22, 2016 at 11:01
- Thanks guys for the useful info! – lgc_ustc Commented Nov 22, 2016 at 11:13
1 Answer
Reset to default 14There are plenty of articles on the largest integer in browser Javascript, but I just wonder things could be different in node.js.
No. JavaScript is JavaScript, a language defined by specification. So the answers you find for "browser JavaScript" also apply to NodeJS.
The maximum integer value that can be represented by a IEEE-754 double-precision binary floating point number (the kind JavaScript uses) is 1.7976931348623157 x 10308, which is available in JavaScript as Number.MAX_VALUE
.
The maximum integer that you can reliably add 1 to and not get the same value back due to a loss of precision is Number.MAX_SAFE_INTEGER
, which is 9,007,199,254,740,991. That is, 9007199254740991 + 1
is 9007199254740992
, but 9007199254740992 + 1
is also 9007199254740992
. There are much larger integers that can be held (see above), but the gaps between them grow as the value increases.