3
DeWil
6y

Is there actually a proper way to do Math in Javascript, without parsing every value to avoid something like
"1" + 3 = 13 ?

Comments
  • 4
    Yes, you make sure your numbers are numbers when you need to do number stuff with them. parseInt or parseFloat it. If you need to string stuff with them make sure they're strings.

    Just like in all other languages
  • 0
    @inaba Seems good, thank you.
  • 6
    Replacing it with a real programming language should fix it.
    *burns*
  • 3
    Use typescript
  • 3
    @wholl0p
  • 0
    @rabbi I should probably take a look at Typescript 🤗
  • 1
    @rabbi Even Typescript has some gimmicks I don't understand sometimes.
  • 1
    @rabbi using typescript would still mean you would have to parse your strings to numbers. It does not help in that regard
  • 1
    @inaba Yes, but it will throw an error if you try '1' + 3 instead of just silently deciding that it should be 13.
  • 0
    @rabbi Yet that would still require him to, and I quote, "parsing every value". It's like suggesting jquery to sum two numbers.
  • 2
    (first: number, second: number, third: number) => first + second + third;
Add Comment