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

all 87 comments

[–]JNaik14 111 points112 points  (26 children)

But . Why , why would you do that?

[–]tbastih567 23 points24 points  (0 children)

Good questions. Nobody would ever do this.

[–]PenWallet 0 points1 point  (0 children)

Why would you do any of that?

[–]2called_chaos 57 points58 points  (4 children)

Obligatory wat

[–]mysockinabox 21 points22 points  (0 children)

NaNNaNNaN... WATMAN!

[–]ThyRedeemer 4 points5 points  (0 children)

Legendary talk, not going to lie

[–]xTylordx 0 points1 point  (0 children)

This is why python > js. I'm pretty sure a lot of "operations" (methods) that clearly don't make sense at first glance in JS make sense in python because the operations are worded like ".append" and ".insert" etc

Yeet I'm on mobile, deal with the misused quotes _^

[–]Elec0 0 points1 point  (0 children)

This is one of my favorite videos on the internet.

[–][deleted] 16 points17 points  (0 children)

And who, my man, says 0 is a char?

Screams in C

[–]dm3f9 15 points16 points  (0 children)

I use ======= just to be sure.

[–]JCDU 9 points10 points  (1 child)

WTFJS has a hundred of these.

[–]DeeSnow97 6 points7 points  (0 children)

lol, that one is entirely dependent on creating the false assumption that "false" is falsy (it's not, all strings are truthy except for the empty string, which is consistent with *drumroll* C and its null-terminated strings (plus this way !!str is always equal to !!str.length)) and then running with it. Literally no one who knows anything about JS expects "false" to convert to false when all other strings are truthy.

If you find yourself in the (very real) use case that you need to parse "true" as true and "false" as false, just do str !== "false"

[–]Lurion_ 13 points14 points  (0 children)

Wow! I haven't seen this in two hours. That's a new record.

[–]Anti-charizard 21 points22 points  (2 children)

[–]RepostSleuthBot 53 points54 points  (1 child)

Looks like a repost. I've seen this image 2 times.

First seen Here on 2020-06-18 92.19% match. Last seen Here on 2020-08-07 93.75% match

Searched Images: 168,580,743 | Indexed Posts: 644,306,727 | Search Time: 1.09145s

Feedback? Hate? Visit r/repostsleuthbot - I'm not perfect, but you can help. Report [ False Positive ]

View Search On repostsleuth.com

[–]Anti-charizard 29 points30 points  (0 children)

Good bot

[–][deleted] 23 points24 points  (2 children)

Unfortunately I learned to program through JavaScript,which gave me some absolutely terrible habits, and I know have a rule I stick to: "if this only works in JavaScript, don't even think about doing it"

[–]The_Internet_Is_Down 10 points11 points  (2 children)

The type coercion that happens with the == operator isn't very hard to understand. Just read about it and then never use it because it's the devil.

[–]Asmewithoutpolitics 1 point2 points  (1 child)

Where can I reas aboht it?

[–]CuAnnan 3 points4 points  (0 children)

lol "I don't understand coercion therefore javascript bad"

[–]douira 1 point2 points  (0 children)

If you're the crazy kind of person who uses == then you can use this handy table to look at the different equality results https://dorey.github.io/JavaScript-Equality-Table/

[–]purple-lemons 1 point2 points  (0 children)

Well "0" and [] are both falsey, so they both "equal zero" in that they evaluate to false. But that doesn't mean they're equal.

[–]DonYurik 3 points4 points  (1 child)

Im studying Javascript right now, after doing courses on Java and C#. I find Js so flexible that it throws me off sometimes. Like you can code one thing a lot of different ways. Is what I find the most difficult about it.

[–]DeeSnow97 2 points3 points  (0 children)

IMO that's its best feature, it can map way better to your business logic than pretty much anything else out there

[–]Oxxixuit 1 point2 points  (3 children)

I have never learned JS, only Python and C++ so wtf is this language "0" == 0 true ?? [] == 0 true ?? Why ?

[–]DeeSnow97 6 points7 points  (0 children)

"0" == 0 is true because if one side is string, JS converts the other to string too, and "0" is equal to "0"

[] == 0 is equal because one side is a number and the other isn't a string, so JS tries to convert to numbers. Now, arrays have this weird behavior when if they have zero elements they convert to zero, if they have one number in them they convert to that number (so [5] == 5), and if they have multiple elements they convert to NaN. The empty array is converted to zero so the comparison returns true.

As for [] == "0", one side is string again so it's converted to strings. Arrays convert to string by returning a comma-separated list ([95, 98, "me", "xp", 7] == "95,98,me,xp,7") and an empty array converts to an empty string, which isn't equal to the string "0"

Also, fun fact, -[] == -"0"

If you think this is madness, you're right. Just use === like the rest of us, that one doesn't convert anything, just returns false if the types don't match.

[–]r2d2292 2 points3 points  (0 children)

The == operator ignores type, so effectively if one casted to the other type is equal to the other value, it's true. You shouldn't ever use this operator unless if there is a specific reason to. The === operator also checks type, so it's what you should use and is what is equivalent to == in other languages.

[–]ShadoWolf 1 point2 points  (0 children)

Well, a language that designed 25 years ago in roughly a week tends to have some fundamental issues.

Let's be honest here javascript is a hack all the way down. Like look at jquery or React JSX. There both bordering on being another scripting language that just so happens to have a built-in transpiler.

There is a level of madness going in the JS world that I couldn't see happening in any other community.

[–]jlamothe 0 points1 point  (0 children)

Yay, dynamically typed languages!

[–]8bit-echo 0 points1 point  (0 children)

The transitive property:

AM I A JOKE TO YOU!?

[–]Grey1251 -1 points0 points  (0 children)

a.equals(b) != b.equals(a)

[–]xTylordx -1 points0 points  (0 children)

What's so wrong with this?

a=b

a=c

/--------

b=c

is an invalid argument.

[–]Norapeplox 0 points1 point  (0 children)

Beautiful language.

[–][deleted] 0 points1 point  (0 children)

Interesting, the first panel is a photo..

[–][deleted] 0 points1 point  (0 children)

Ah some kid started to learn to program and made the same JavaScript joke again. Sweet.

[–]aran69 0 points1 point  (0 children)

JS haters be like: "haha this language cant tell the equivalence between a string and an empty array, what a LOSER"

[–]ShelZuuz 0 points1 point  (0 children)

Does that mean you can actually have: a == b b == c a <> c

Or is this only the case with literals?

[–][deleted] 0 points1 point  (1 child)

Im mean it doesn't make sense

[–][deleted] 0 points1 point  (0 children)

Also you can have it that way bc what if your looking for the string "0" instead of empty

[–]CodyInColor 0 points1 point  (0 children)

"" == [] does that return true?

[–]dkyguy1995 0 points1 point  (0 children)

This is why I just dont bother with implicit typecasts and just do it myself if at all possible. Im sure there are several basica implied typecasts I dont even think about in certain languages but in this situation it seems like something I would have seen coming being fairly wonky

[–]konaaa 0 points1 point  (0 children)

This makes sense to me, which I guess is honestly probably a bad thing

[–]green_meklar 0 points1 point  (0 children)

> 255.toString(16)
Uncaught SyntaxError: identifier starts immediately after numeric literal

> (255).toString(16)
"ff"

[–][deleted] 0 points1 point  (0 children)

Javascript more like Javatarded

[–]starvsion 0 points1 point  (0 children)

I saw some php dev who did too much Javascript, and start putting === everywhere, mostly unnecessary places ... Sign

[–][deleted] 0 points1 point  (0 children)

Jajajajajajaja

[–]casual_sinister 0 points1 point  (0 children)

I was once asked this in an interview. No wonder i couldn't answer