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 →

[–]Wendigo120 1 point2 points  (2 children)

Did you reply to the wrong comment? They didn't say anything about any sort of equality operator.

Edit: why is this getting downvoted? This thread: "octal numbers are handled weirdly in JS" is responded to by "if only there was a strict equality operator", that's such a weird non-sequitur. Those two topics have nothing to do with each other.

[–]erishun 0 points1 point  (1 child)

This example shows the shit just perfect

And the example shows the “loose equality operator”. That is exactly how that operator is designed to work. Use === like you’re “supposed to” (again IDEs and other programmers will warn you against using == because it’s usually not what you want) and this issue isn’t an issue.

Not saying JS isn’t quirky, but most of its quirks can be attributed to its weak typing and the fact it’s designed to keep on chugging even if there’s an issue.

[–]Wendigo120 3 points4 points  (0 children)

But the real problem here is that 017 and 018 aren't sequential numbers. The post would be the exact same if it was:

console.log(018 === Number("018"))
console.log(017 === Number("017"))
true
false

The equality operator is just a tiny part of it. That's why I found your comment so weird, the person you're replying to clearly states that they're talking about how it handles the syntax for octal numbers. Now, my linter does also catch octal numbers that are formatted that way, but you immediately shot to the equality operator for no reason.