Re:Be careful with JS numbers
by jre on Sunday January 13, 2013 @03:13PM
(#5051727)
It's not really about static typing or not, it's really about JS having some really strange and counter-intuitive behaviours in a lot of cases (numbers, default method scope, truthy values, ...).
Part of it is probably due to the fact that the syntax looks so much like C and Java that you'd except it to behave the same. Part of it seem to be that it's hard to fix things without breaking existing codebases.
[ Parent
| on HN ]
Re:Be careful with JS numbers
by ricardobeat on Sunday January 13, 2013 @03:40PM
(#5051788)
Every language has it's own quirks, some even weirder than JS. The floating point "errors" are common to a hundred programming languages, that's why BigNum classes/extensions exist.
The problem in this case is not floating point approximations. It is that some functionalities (parseFloat vs parseInt, ++, 45.0 being printed 45 in most browsers) makes the user believe that JS has an integer type.
Re:Be careful with JS numbers
by ricardobeat on Sunday January 13, 2013 @05:16PM
(#5052111)
Square peg in a round hole, you wouldn't try to understand Haskell with a Ruby background either.
Since it has no types per se, it doesn't make much sense to think of an 'integer type'. Javascript only has a number primitive, which is a IEEE 754 float.