zlacker

[parent] [thread] 8 comments
1. batter+(OP)[view] [source] 2020-04-03 08:31:02
Also, how does he know that number-containing strings will work if the title isn't "Test123"??
replies(1): >>_-____+r
2. _-____+r[view] [source] 2020-04-03 08:35:09
>>batter+(OP)
"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+I >>yread+d3 >>TeMPOr+f3
◧◩
3. batter+I[view] [source] [discussion] 2020-04-03 08:38:25
>>_-____+r
Wow, I learned something in here and I was just "trolling" in the test thread!

Thanks!

◧◩
4. yread+d3[view] [source] [discussion] 2020-04-03 09:11:42
>>_-____+r

   > parseInt("0123Test")
   123
   > 0123
   83
parseInt is actually the adult in the room
replies(2): >>TeMPOr+h3 >>hurflm+UA
◧◩
5. TeMPOr+f3[view] [source] [discussion] 2020-04-03 09:12:33
>>_-____+r
That leading 0 is also useful for the things that try to interpret the string as number first and are able to understand octal.
◧◩◪
6. TeMPOr+h3[view] [source] [discussion] 2020-04-03 09:12:57
>>yread+d3
In a way. The convention is that 0123 is "123" in octal.
replies(1): >>yread+F7
◧◩◪◨
7. yread+F7[view] [source] [discussion] 2020-04-03 10:10:01
>>TeMPOr+h3
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+ga
◧◩◪◨⬒
8. sweene+ga[view] [source] [discussion] 2020-04-03 10:45:34
>>yread+F7
Because C does.
◧◩◪
9. hurflm+UA[view] [source] [discussion] 2020-04-03 14:37:22
>>yread+d3

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