+ 4

Why the output of this code is 33? can someone explain it for me?

console.log(011+24);

6th May 2019, 10:46 AM
Mo3n
Mo3n - avatar
2 Respostas
+ 6
well, I searched stack overflow for this question, and found the answer: Putting a zero before the number causes the number to be interpreted in octal. This means that 010 is 1 * 8 + 0 * 1 aka 8. It is similar to writing 0x10 for a hex value which would result in 16 when out putted in base 10 (the default). There is no prefix for binary so you would have to use something like parseInt('10', 2)resulting in a value of 2.
6th May 2019, 10:49 AM
Mo3n
Mo3n - avatar