Why JS 45-033 =18 and 45-33 =12?

Hi All,

I am just trying out simple math operations using JavaScript and ran into a strange problem. Could you please help me here?

Why Javascript output of 45-033 = 18 instead of 12

and 45+033 = 72 instead of 78

Thanks!

2 Likes

033 isn’t a valid decimal number. JS interprets it as an octal number. And 033 as an octal number is the same as 27 (decimal number). So: 45-27=18.

5 Likes

033 is base-eight number and it equals 27 in decimal.

4 Likes