Why does 0154 === 108? [duplicate]
What's happening here and why?
document.write(0154); // === 108
Numbers that begin with 0 are considered octal (base-8) numbers.
base 8 [0154] = base 10 [108]
but if you had used a number that had an 8 or 9 you wouldn't have seen this problem since that neither 8 nor 9 is an octal digit.
0154 is octal. 1*64 + 5*8 + 4 = 108.
its octal number. octal=0154 & decimal is=108
It is printing out the octal equivalent of what you wrote because it started with 0. Try 0001 (prints out 1), 0010 (prints out 8), 0011 (prints out 9)
精彩评论