1

I was trying to do maths based on variables and use the outcome. The input sometimes has padding with leading zeroes at the start of it. Today while debugging my code I have found out the following; eval("1*010 + -9") evaluates to -1 while eval("1*10 + -9") evaluates to 1

I do not have any idea how this could be possible since these following evaluations work as intended

eval("1*009 + -9") evaluates to 0

eval("1*011 + -9") evaluates to 2

Any explanation would be helpful, thanks for sharing your time.

xDeathwing
  • 139
  • 13
  • 2
    `010 === 8` (octal). Don't use leading zeros, call `Number` directly on the text, eg `Number('010')` ( `=== 10`) – CertainPerformance Dec 29 '18 at 22:22
  • Yeah I have just realised aswell, well it is odd that the javascript treats such numbers as octal for no reason. Thanks for the quick reply – xDeathwing Dec 29 '18 at 22:29

0 Answers0