3 ms·
I've spent days tracking down a bug around a color picker widget, turns out JS was implicitly casting my string value to octal. I've worked with heaps of toy l
by hnzix 9y ago
I've spent days tracking down a bug around a color picker widget, turns out JS was implicitly casting my string value to octal.
I've worked with heaps of toy languages like Lingo, vbscript and ActionScript, and nothing has made me as viscerally angry as JavaScript (ok maybe PHP's complete lack of naming consistency). JS is an accident of history that has somehow become the de facto standard.
I guess worse really is better.
- k__ 9y agoThat's like saying group XY of people is bad because you got mugged by one person of that group one time. While I understand that a problem like this is unnerving, it isn't the rule.
- kaoD 9y ago> turns out JS was implicitly casting my string value to octal How exactly? I'm really curious. AFAIK it's pretty hard for a JS string to be casted into anything (pretty easy the other way around though). I guess maybe parseInt can do that, but that's neither casting not implicit.
- hnzix 9y agoLooks like it's been fixed in ES5. From memory I was performing an operation on a html color string and if you clicked a color with a certain prefix it would crash. I could easily reproduce the bug but it took me forever to work out why JS was choking. I think I added in some ridiculous string padding to prevent the auto casting. https://stackoverflow.com/questions/2547836/why-doesnt-an-octal-literal-as-a-string-cast-to-a-number https://stackoverflow.com/questions/2547836/why-doesnt-an-oc...
- rwaldron 9y ago> Looks like it's been fixed in ES5 That was published 9 years ago.
- phpnode 9y agoPresumably by calling parseInt('010') which used to detect zero leading strings as octal.