DEV Community

Cover image for #27 Guess The Output ???
Sham Gurav
Sham Gurav

Posted on

#27 Guess The Output ???

⭐ Reply with correct answer & Bonus points for explanation ⚡

💡 Correct answer with detailed explanation will be updated in comments after 48 hours.

#27 Guess The Output???

Code -

console.log((055-35)-5);
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

Collapse
 
jayjeckel profile image
Jay Jeckel

It can't be 15 as one would intuitively think. So, thinking what kind of wrong thing javascript could do, I'm guessing the leading zero is treated as some kind of literal prefix that changes the base of the number. Fives wouldn't be valid for binary, so possibly hex, which would make 55 actually equal to decimal 85 and the final answer 45.

But that would still be too logical, as hex is generally useful, so I'm guessing it isn't hex, but a less used base... so maybe base 12 or 8. I can't think of the name for base 12, but octal has a simple name and isn't very useful, so I'm going to guess that it's octal.

Then octal 055 actually equals decimal 45 and the result is 45 - 35 - 5 == 5.

Collapse
 
shamgurav96 profile image
Sham Gurav

Your answer is correct and Your guessing game is on point. Getting kind of Sherlock Holms vibess .....

Collapse
 
marifm1986 profile image
Arif Matubber

5

Collapse
 
shamgurav96 profile image
Sham Gurav

That's absolutely Correct !!!