Why do these JavaScript object list properties return the wrong value?

I don't understand why the code below returns seemingly incorrect values ​​(150 instead of 100):

var price = {
  33427009000001024: 100,
  33427009000001025: 150,
  33427010000001026: 200
};
alert(price[33427009000001024] + "," + price["33427009000001024"]);
Run code

Displayed Values: 150,150

I fixed it by including the properties of the object in quotation marks:

var price = {
  "33427009000001024": 100,
  "33427009000001025": 150,
  "33427010000001026": 200
};

But I don’t understand if quotes are really needed / needed and why am I not getting an error, but just the wrong values?

+4
source share
2 answers

your integer value is greater than the maximum value of integers

therefore rounded to the same values

33427009000001024 == 33427009000001025 // outputs true
33427009000001024 === 33427009000001025 // outputs true
+4
source

JavaScript (, ). , 33427009000001025 33427009000001024 100 150.

, ( 4 ).

+1

Source: https://habr.com/ru/post/1625787/


All Articles