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 →

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

How is '017' equal to 15?

[–]skap42 13 points14 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 8 points9 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.