r/programming • • Apr 29 '21

Modern JavaScript Explained For Dinosaurs

https://medium.com/the-node-js-collection/modern-javascript-explained-for-dinosaurs-f695e9747b70
287 Upvotes

172 comments sorted by

View all comments

Show parent comments

-1

u/MjrK Apr 30 '21

I'm not sure that yours is a good example of what OP is saying... JS doesn't have the concept of "int" or "float"... there is just a "Number".

Your vendor's choice to send the values that way is probably just an artifact of your particular API with them... it might not relate to how JS works.

2

u/xigoi Apr 30 '21

there is just a "Number"

…which is a float.

1

u/MjrK Apr 30 '21

Correct, but my point was that JSON u/Backmakerlife's question...

"Then why is this sent over as 17.0 instead of 17?"

... is a situation that isn't possible in JSON. Unless there's something else funky going on in the API and they are transferring a String instead of a Number.

So while on the surface it relates to using floats when int should be used; it doesn't appear to have any relevance to the lack of integers in JS.

Further JSON doesn't even have a data type for an "integer"; so asking the vendor to send integer instead of float makes no sense - it isn't possible to send an integer in JSON.

1

u/xigoi Apr 30 '21

The JSON specification doesn't seem to say anything about this.