Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does 0154 === 108? [duplicate]

What's happening here and why?

document.write(0154); // === 108
like image 650
Shaz Avatar asked Feb 15 '11 07:02

Shaz


3 Answers

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.

like image 119
typo.pl Avatar answered Nov 19 '22 12:11

typo.pl


0154 is octal. 1*64 + 5*8 + 4 = 108.

like image 35
awm Avatar answered Nov 19 '22 12:11

awm


its octal number. octal=0154 & decimal is=108

like image 1
Manish Trivedi Avatar answered Nov 19 '22 13:11

Manish Trivedi