zlacker

[parent] [thread] 7 comments
1. _-____+(OP)[view] [source] 2020-04-03 08:35:09
"0123Test" is a better number-containing string for testing, to catch out things that try to interpret the string as a number first and then as a string if that fails. For example, JS's insane parseInt function will give you 123 for "0123Test".
replies(3): >>batter+h >>yread+M2 >>TeMPOr+O2
2. batter+h[view] [source] 2020-04-03 08:38:25
>>_-____+(OP)
Wow, I learned something in here and I was just "trolling" in the test thread!

Thanks!

3. yread+M2[view] [source] 2020-04-03 09:11:42
>>_-____+(OP)

   > parseInt("0123Test")
   123
   > 0123
   83
parseInt is actually the adult in the room
replies(2): >>TeMPOr+Q2 >>hurflm+tA
4. TeMPOr+O2[view] [source] 2020-04-03 09:12:33
>>_-____+(OP)
That leading 0 is also useful for the things that try to interpret the string as number first and are able to understand octal.
◧◩
5. TeMPOr+Q2[view] [source] [discussion] 2020-04-03 09:12:57
>>yread+M2
In a way. The convention is that 0123 is "123" in octal.
replies(1): >>yread+e7
◧◩◪
6. yread+e7[view] [source] [discussion] 2020-04-03 10:10:01
>>TeMPOr+Q2
Yes, I know that's why I even tried it in console as I was a bit surprised that parseInt doesn't do octal.

Why does js even support octal? I never found octal particularly useful. Speak hexadecimal or die

replies(1): >>sweene+P9
◧◩◪◨
7. sweene+P9[view] [source] [discussion] 2020-04-03 10:45:34
>>yread+e7
Because C does.
◧◩
8. hurflm+tA[view] [source] [discussion] 2020-04-03 14:37:22
>>yread+M2

    > parseInt('0123Test', 8)
    83
you could do it like this, otherwise it uses the default value for the base parameter.
[go to top]