Frontend Development 2 min read

JavaScript JSON Number Handling and Integer Overflow Issues

The article explains how JavaScript interprets JSON values without quotation marks as numbers, demonstrates the difference between numeric and string representations of the same value, and warns that large numeric literals may overflow a 32‑bit integer during internal conversion.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
JavaScript JSON Number Handling and Integer Overflow Issues

JavaScript often treats JSON values that are not enclosed in double quotes as numeric literals rather than strings.

For example, the JSON snippet {"a":987654321} causes the variable a to be interpreted as the integer 987654321 .

When the value is quoted, as in {"a":"987654321"} , the variable a is treated as a string containing the characters "987654321".

Internally, JavaScript converts large numeric literals like 987654321 to a C int type, which is typically 32 bits; numbers exceeding this range can overflow, leading to incorrect results.

The article is originally from the company wiki "老何的1001夜" and is available to Qunar colleagues for further reading.

frontendJavaScriptJSONdata typesinteger overflow
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.