Eval in JS

Why does
eval("076")
eval("076")
return 62?
6 Replies
Jochem
Jochem3y ago
it thinks 076 is an octal representation of a number because of the leading zero just guessing from this one line, but if you're running into this as a bug, you're probably misusing eval and should just use parseInt("076", 10). The 10 forces parseInt to treat the number as a decimal number
13eck
13eck3y ago
It doesn’t “think” it’s octal, it is octal :p
Jochem
Jochem3y ago
I've been doing too much with strongly typed languages, what really is, is a string ;P
13eck
13eck3y ago
Numbers that start with 0 are octal numbers
Jochem
Jochem3y ago
oh wait, I see what you mean, the string is getting run as javascript code because of eval, so "076" isn't a string by the time it's run
Satya
SatyaOP3y ago
I get it now. Thanks
Want results from more Discord servers?
Add your server