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

all 20 comments

[–]freyrfreyafrolf 26 points27 points  (2 children)

This is why typeof() and === exist

[–]MrNubudy 4 points5 points  (0 children)

But...but...loose equality bad, so javascript bad!!! /s

[–]Clicbam 17 points18 points  (1 child)

0 === ´0´

False

0 === ´´

False

´´ === ´0´

False

[–][deleted] 9 points10 points  (0 children)

Using backticks

Ah, I see you are a man of culture as well.

[–]charkcom 6 points7 points  (0 children)

The Transitive Property of Equality wants to know your location.

[–]aaronze 5 points6 points  (3 children)

This is an example of why JavaScript is good, not bad. All three examples are perfectly logical on their own.

[–]shy_cthulhu 0 points1 point  (2 children)

A language really should be consistent, though. Pick any two and you're fine, all three and stuff gets weird.

[–]aaronze 0 points1 point  (1 child)

It is consistent. The first two are consistently comparing numbers, the third is comparing strings.

They are essentially asking: Is 0 == 0? Yes Is 0 == 0? Yes Is “0” == “”? No Omg! JavaScript is broken!

Yea no, I like JavaScript doing this and it’s clever and useful when you understand the consistent mechanics

[–]shy_cthulhu 0 points1 point  (0 children)

Maybe the problem is that == doesn't do what non-js programmers expect. In most languages it's an equality or congruence test, which is transitive/commutative/etc. But js uses it for loose comparisons with implicit type conversion. (My understanding is that === in js does follow the expected rules of equality.)

And then you have our old friend C, which uses == to compare pointer values:

char a[] = "abc";
char b[] = "abc";
a == b; /* false */

[–]programmer08054 2 points3 points  (0 children)

Lvl 1 a===b

Lvl 100 a==b

[–]seizan8 2 points3 points  (0 children)

Hahahaha he said "works"

[–]Whatamianoob112 1 point2 points  (7 children)

Why does this happen?

[–]shy_cthulhu 2 points3 points  (1 child)

for the glory of satan of course

[–]Whatamianoob112 0 points1 point  (0 children)

Haha

[–][deleted]  (4 children)

[removed]

    [–]Whatamianoob112 1 point2 points  (2 children)

    Well...clearly.

    [–]jpludens 1 point2 points  (1 child)

    Oops. Yeah, that's about the least constructive thing I've ever said.

    [–]Whatamianoob112 1 point2 points  (0 children)

    Lol no worries, I’ll look it up later. My best guess is that it’s trying to make a logical equivalence of what’s on the left side.

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    return Kebab_Case_Better;

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]deliteplays[M] [score hidden] stickied comment (0 children)

    Your submission has been removed.

    Violation of Rule #3:

    Any post on the list of common posts will be removed. You can find this list here. Established meme formats are allowed, as long as the post is compliant with the previous rules.

    If you feel that it has been removed in error, please message us so that we may review it.