JavaScript · Senior · Question 31 of 75

Why does 9007199254740993 === 9007199254740992 return true?

Explanation

A double has a 53-bit mantissa, so not all integers beyond 2^53 are representable. Large IDs from APIs (e.g. 64-bit ones) come in JSON as strings or are handled via BigInt, otherwise they're silently corrupted. Check with Number.isSafeInteger.

Further reading

Problem with a question

JavaScript · Senior · question 31

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz