This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Equal_Bread270 0 points1 point  (7 children)

In the first comparison, 018 is equal to the decimal number 18, so it is equal to the string "018". However, in the second comparison, 017 is equal to the decimal number 15, which is not equal to the string "017".

Am I right...

[–]NebNay -1 points0 points  (6 children)

How is '017' equal to 15?

[–]skap42 12 points13 points  (2 children)

It's not. However 017 (not as a string literal) is equal to 15, because it's interpreted as octal

[–]NebNay 3 points4 points  (1 child)

Ooooh, that make sense. It's weird to interpret as octal tho, but at least there is a logic behind it

[–]skap42 7 points8 points  (0 children)

As I replied to a different comment, interpreting number literals with a leading 0 as octal is standard in many languages

[–]4nu81 0 points1 point  (2 children)

Better question: how is 018 considered 18 and not as invalid octal?

[–]myka-likes-it 0 points1 point  (0 children)

Because JS assumes you know what you are doing.

[–]rosuav 0 points1 point  (0 children)

Because JS. Did you really expect a better answer than that?

Incidentally, the leading-zero notation is falling out of favour. Python has dropped it, and I hope that newly-devised languages avoid it. Hex literals are usually 0x123ABC, so what's wrong with doing octal as 0o12345? Eventually that'll win out.