4

Every damn day I learn something new in javascript.

Comments
  • 0
    No real surprises here, although can anyone explain the last one?
  • 2
    @theuser In every example where it works, the number is at the first place.
  • 3
    @theuser the ending non-numeric values are handled like units, as in “32cm” gives you 32.
  • 0
    @010001111 Ah gotcha, its the inch unit.
  • 2
    @theuser As far as I know it just parses the string until it encounters the first non-numerical symbol and ignores the rest.
  • 0
    @010001111 From what I've seen, it doesn't matter if it's a unit or not, the string would just be left out so the result would always be the first number if it's in the index 0 of the string (no matter if you have other numbers after some non-numeric characters).
  • 1
    Note that if you have a hexadecimal string and want to parse it to an int, remember that the second argument to parseInt is an optional radix (in case you were looking at the parsing of “1a” and sad that it didn’t come out as 26).
  • 0
    @Berkmann18 that’s the intend, you can’t standardize every possible unit there is, besides, there are some self made or non-related units from completely different sectors. That’s why it doesn’t care about the end, but does for the beginning.
  • 0
    @OneOrZero A stringified zero is not falsey
Add Comment