Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Numbers

Tags:

javascript

I read on the MDN Reintroduction to JavaScript that JavaScript numbers are a floating point precision type only, and that there are no integers in JavaScript. Yet JavaScript has two functions, parseInt and parseFloat`. After doing a bit of Googling, I'm getting mixed results.

So, does JavaScript abstract away the details of integers and doubles in its number type, or does JavaScript only have double precision Number types and the functions parseInt and parseFloat are poorly named?

like image 1000
LandonSchropp Avatar asked Apr 19 '26 20:04

LandonSchropp


1 Answers

does JavaScript abstract away the details of integers and doubles in its number type, or does JavaScript only have double precision Number types

Yes.

A JS engine may choose to optimise some uses of Number to use integer math behind the scenes, but as far as JS apps are concerned, there is only Number, and it always behaves exactly like an IEEE double-precision float.

and the functions parseInt and parseFloat are poorly named?

Arguably, but parseFloatThatHappensToBeAWholeNumber would be a bit unwieldy. :-)

like image 158
bobince Avatar answered Apr 22 '26 09:04

bobince



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!