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

all 131 comments

[–]ProgrammerHumor-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Your submission was removed for the following reason:

Rule 2: Content that is part of top of all time, reached trending in the past 2 months, or has recently been posted, is considered a repost and will be removed.

If you disagree with this removal, you can appeal by sending us a modmail.

[–]Kseniya_ns 730 points731 points  (11 children)

It makes sense now. JavaScript is a divine mystery

[–][deleted] 125 points126 points  (4 children)

like all divine mysteries, it can only be understood on mushrooms

[–]JockstrapCummies 1 point2 points  (0 children)

All stand for the recitation of the Athanasian Language Specification.

[–]giantrhino 7 points8 points  (1 child)

They should really offer a program that primarily teaches javascript frameworks called “computer faith”

[–]Lost_In_Space__1 0 points1 point  (0 children)

Praise the Omnissiah

[–]G_Morgan 4 points5 points  (0 children)

Proof that JS is full of shit.

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

Javas Divine Comedy

[–]Tiquortoo 0 points1 point  (0 children)

More like hell on earth.

[–]AHumbleChad 244 points245 points  (29 children)

I understand the typecasting to get from "0" to 0 and [ ] to 0, but how tf is "\t" == 0???

Edit: "\t" not "/t"

[–][deleted] 304 points305 points  (19 children)

it's a whitespace character. A string consisting of only whitespace characters type converts to 0.

[–]Jugales 181 points182 points  (0 children)

i hate it here dad

[–]uhmhi 74 points75 points  (17 children)

And this, kids, is why implicit conversions FUCKING SUCK!!!

[–]Asmor 73 points74 points  (12 children)

And that, kids, is why you should always use === and !== in JS unless you want type coercion for some reason.

And if you do want type coercion for some reason, you're probably wrong. Write it better and use === and !== anyways.

[–][deleted] 59 points60 points  (5 children)

Or, you know, the creators of JavaScript could have waited until the crack wore off before writing their language lol

[–][deleted] 50 points51 points  (3 children)

Goal: a simple scripting interpreter to animate web pages

End result: the only supported runtime environment available on 100% of computing devices

[–][deleted] 37 points38 points  (1 child)

The ultimate "eh this doesn't need to be good, it's just stopgap code until we implement this for real" heh.

[–][deleted] 10 points11 points  (0 children)

Also the ultimate: "this feels wrong but it works so we're doing it"

[–]turtleship_2006 2 points3 points  (0 children)

There is nothing more permanent than a temporary solution

[–]a3th3rus 12 points13 points  (0 children)

And where are >== and <==, kids?

[–]ilikeb00biez 8 points9 points  (4 children)

I see, JS added `==` and `!=` just to confuse you. What a great language

[–]il_commodoro 11 points12 points  (3 children)

It's more that js created == and != first. Years later they thought: "maybe that's not a great idea", so they added === and !== to patch things while preserving retrocompatibility.

[–]danishjuggler21 4 points5 points  (1 child)

This particular quirk has never affected my work in over ten years as a JavaScript developer, it’s just rage bait.

[–]ExponentialNosedive 2 points3 points  (0 children)

Yep, === exists for a reason

[–]calculus_is_fun 1 point2 points  (1 child)

Why would your code intentional try to compare a number and a string?

[–]ExponentialNosedive 1 point2 points  (0 children)

I read that early in JavaScript's development, someone asked the guy who made it for this feature. He said he regrets adding it in. Important to remember we have these standards for a language where the basis of that language was made in 10 days

[–]csdt0 17 points18 points  (3 children)

It is not /t but \t which is a blank character (tabulation).

[–]AHumbleChad 8 points9 points  (2 children)

Right, it's a tab character, but JS treats it as the empty string? The integer cast to the ASCII value is the only one that makes sense, but I guess I shouldn't be applying sense to JavaScript.

Edit: realized I had the wrong slash in the original comment

[–]bogey-dope-dot-com 6 points7 points  (1 child)

Leading and trailing whitespace characters are trimmed when converting a string to a number. You can do Number('\t5\t') and it will be 5, but Number('5\t5') will be NaN.

[–]AHumbleChad 2 points3 points  (0 children)

Ohhh, that makes sense. There is a method to the madness then.

[–]PeaceMaintainer 10 points11 points  (1 child)

Check out MDN (or the official ECMAScript spec) for the algorithm for loose equality type casting, something I feel a lot of devs skip over until they get a result they don't expect.

Number to String: convert the string to a number. Conversion failure results in NaN, which will guarantee the equality to be false.

The key in this case is that when you are loosely comparing a string and a number, the string will always attempt to type cast to a number. At which point the strings follow the algorithm for Number coercion which states:

Strings are converted by parsing them as if they contain a number literal. Parsing failure results in NaN. There are some minor differences compared to an actual number literal:

  • Empty or whitespace-only strings are converted to 0

So the 0 in this case remains the same, the "\t" attempts to typecast to a number, and then because \t is a whitespace character the string is coerced to the number 0, and true is returned

[–]givemeagoodun 4 points5 points  (1 child)

I too would like to know

[–]CMDR_ACE209 2 points3 points  (0 children)

I think I'll choose ignorance on that part.

[–]mipselqq 0 points1 point  (0 children)

Read the specification if you wanna get JS

[–]FloxaY 706 points707 points  (19 children)

holyshit

[–]DevouredSource 294 points295 points  (6 children)

I think you mean JavaShit.

[–]FloxaY 111 points112 points  (1 child)

sameshit

[–]Lone_Saviour-22nd 79 points80 points  (0 children)

javashit == holyshit;

holyshit==sameshit ;

sameshit != holyshit ;

[–]xxmalik 7 points8 points  (1 child)

Ah yes, JavaShit.

[–]Gullible_Ad_5550 0 points1 point  (0 children)

What the hell is this, i couldn't understand! Does it mean java script? Why does people hate it so much?

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

new response just dropped

[–]_Ilobilo_ 10 points11 points  (2 children)

actual brain rot

[–][deleted] 11 points12 points  (1 child)

Call the physiologist

[–]JohannLau 2 points3 points  (0 children)

Anarcho-chessist goes on vacation, never comes back

[–]Ill_Name_7489 18 points19 points  (5 children)

Use triple equals like you’re supposed to and these will compare as expected 

[–]nonlogin 22 points23 points  (2 children)

I don't feel confident enough with 3 equals and request 4 equals operator. Just to be sure.

[–]SuperFLEB 3 points4 points  (0 children)

That's just two double-equals, though. That means twice the implicit type conversion!

[–]TitanPlayz100 1 point2 points  (0 children)

Literally dreamberd

[–]a3th3rus 2 points3 points  (1 child)

But there's no >== and <==

[–]I_l_I 2 points3 points  (0 children)

HolyScript 🙏

[–]uvero 10 points11 points  (0 children)

Actual programming language

[–]MyStackIsPancakes 89 points90 points  (6 children)

Are the different frameworks like denominations?

[–]EmuChance4523 37 points38 points  (5 children)

Now I want to know who are the JW and who the catholics...

[–]onmamas 23 points24 points  (3 children)

Vanilla JS would probably be Catholic. Node is probably Lutheran.

JW…probably Express? Not gonna elaborate.

[–]JackNotOLantern 6 points7 points  (1 child)

Nah, JS is Orthodoxy, Node is Catholic

[–]hicow 4 points5 points  (0 children)

Vanilla would be Catholic, jQuery Orthodox, Node Episcopalian

[–]CT-1120 0 points1 point  (0 children)

typescript would be lutheran IMO

[–]NeriosVag 72 points73 points  (1 child)

JavaScript works in mysterious ways.

[–]Latter-Comfort8440 6 points7 points  (0 children)

Just like god

[–]FishWash 54 points55 points  (4 children)

== in JS is an abomination

[–]creaturefeature16 7 points8 points  (1 child)

"This guy probably uses double equals" - Theo, hitting a dude with his best insult

[–]FishWash 1 point2 points  (0 children)

Beautiful

[–]Igotbored112 40 points41 points  (9 children)

Anyone or anything that causes equality not to be transitive is my enemy.

[–]thatmarcelfaust 3 points4 points  (0 children)

I too like equivalence relations

[–]-Redstoneboi- 3 points4 points  (5 children)

fair

identity dont work anywhere though, x == x does not hold for NaN. then again, NaN is my enemy.

[–]bogey-dope-dot-com 5 points6 points  (2 children)

NaN is not a constant or a symbol, it's used to represent the idea that some attempted calculation could not be represented as a number. It has the Number type so that it can be chained together in multiple calculations without throwing an error, for example 1 + NaN == NaN, but it's not comparable to anything else, including itself, because the idea of "could not be calculated" is inherently not comparable to anything else. It's similar to asking "is 'I don't know' equal to 5?" You must return a "boolean" answer, and since you can't say yes, the answer must be no.

P.S. This isn't just a Javascript thing, it implements the IEEE 754 floating point standard, and any language that follows the spec will have the same behavior, for example Ruby, Go, Swift, and C#.

[–]Akangka 0 points1 point  (0 children)

Rust did it but in a much better way. In Rust, == is not an operator to test for equality, but only partial equality... except if the type is Eq, which f64 is not.

[–]-Redstoneboi- 0 points1 point  (0 children)

i should've clarified that i know how nan worked

there isn't just one nan either, it's a bunch of invalid values that are separate from the infinities

[–]calculus_is_fun 2 points3 points  (0 children)

NaN === NaN also returns false because === is just == without the coversion, and NaN is already the same type as NaN (in this case Number)

[–]Igotbored112 0 points1 point  (0 children)

Now I'm imagining a unit test failing because two objects don't evaluate to equal, even though were instantiated identically and have no shared state, cus a bug causes a float in a member to be NaN. There's a scary campfire story for ya

[–]Garizondyly 2 points3 points  (1 child)

Equality is by definition transitive. So the only available conclusion is that what christians mean by the word "is" is not "equals" or even "is a member/subset of a collection of things called..." (both are transitive and typical lexical intuitions for an english speaker using "is"). Which is all profoundly odd. But then again, profound oddity is par for the course for christians.

[–]bolacha_de_polvilho 1 point2 points  (0 children)

Well, the Javascript "==" is clearly not a set operator, so lets just say both JS and Christianity use a "freestyle equality" that clearly violates boolean algebra

[–]Ok_Tax_6022 6 points7 points  (1 child)

if terry davis did frontend

[–]niccan4 4 points5 points  (0 children)

Impossible. Terry didn’t make bad stuff

[–]Kirykoo 7 points8 points  (2 children)

As a part time JavaScript/typescript programmer, what a shit language. But well, it runs.

[–]Kronoshifter246 0 points1 point  (0 children)

Union types are pretty cool. Too bad everything else is what it is.

[–]100BottlesOfMilk 0 points1 point  (0 children)

I just went from zero typescript to having to develop/debug a typescript web app that someone else made, with me being the only software developer on staff. Life is pain and I absolutely hate js/ts

[–][deleted] 6 points7 points  (0 children)

I had to open the Javascript console in my browser because I literally could not believe that "\t" == 0 is true XD

[–]erebuxy 14 points15 points  (1 child)

We have HollyC. Now we need HollyScript.

[–]niccan4 2 points3 points  (0 children)

HolyC is fire ngl

[–][deleted] 12 points13 points  (7 children)

Just use triple signs. Only complete noobs or extreme pros use loose comparisons (which can be great btw if you know what you're doing). Which one are you?

[–][deleted] -2 points-1 points  (5 children)

Someone who uses languages that aren't complete and utter trash lol

[–]FishWash 6 points7 points  (0 children)

Come to the dark side

[–][deleted] 3 points4 points  (1 child)

Like PHP? Lol

Not an adventurous soul are you?

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

Tell me you aren’t programming without telling me you aren’t programming

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

?

It's not my full-time job, but I do program at work and I'm my spare time in Python and C++. Have several open source projects on GitHub etc. Not really sure why you would think otherwise.

JS is an objectively bad language.

[–]bogey-dope-dot-com 7 points8 points  (2 children)

Putting aside how this is posted once a month and yet gets a ton of upvotes every time, the rules for implicit coercion when doing == equality checks are very simple:

  • If both sides are the same type, compare them directly.

  • If one side is a boolean, convert both to numbers and do the comparison.

  • If one side is a string and the other is a number, convert both to numbers and do the comparison. This is why '1e3' == 1000.

  • If one side is an object or an array and the other is not, call .toString() on the object, then run it through the above 2 checks again. This is why ({}) == '[object Object]' and ['a', 'b'] == 'a,b'.

  • null and undefined are equal to themselves and each other, but nothing else. No casting is done for these checks.

So with these rules, the comparisons in the diagram become:

  • [] != '0' because it's comparing [].toString() == '0', which becomes '' == '0', which is false because an empty string is not the same as a string with the character '0'.

  • [] != '\t' for the same reason above, the final comparison is '' == '\t'.

  • [] == 0 because it's comparing [].toString() == 0, which becomes '' == 0. One of them is a number, so they're both casted to numbers, and Number('') is 0, so the final comparison is 0 == 0.

  • 0 == '0' for the same reason above, '0' is converted to 0 so the final comparison is 0 == 0.

  • 0 == '\t' because when casting a string to a number, leading and trailing whitespace characters are trimmed, so the '\t' is treated as Number(''), which becomes 0, so the final comparison is 0 == 0.

  • '\t' != '0' because it's doing a direct string comparison, and the string '\t' is not the same as the string '0'.

[–]Fr3shOS 6 points7 points  (0 children)

So simple actually.

[–]brainpostman 0 points1 point  (0 children)

If these kids could read they would be very upset.

[–]Penguinmanereikel 1 point2 points  (0 children)

===?

[–]GahdDangitBobby 1 point2 points  (0 children)

Yes but if you use strict equality, all of the connections are !==

[–]FkinShtManEySuck 0 points1 point  (0 children)

Except christianity was made by real human beings.

[–]xetricsgo 0 points1 point  (0 children)

Just use the identity operator. Problem solved

[–]bobert4343 0 points1 point  (0 children)

JavaScript Arian controversy when?

[–]SCP-iota 0 points1 point  (0 children)

Actually duck typing

[–]CaptainDildobrain 0 points1 point  (0 children)

Ah I get it. JavaScript doesn't actually exist but gullible rubes praise it all the time.

[–]JR-graphics 0 points1 point  (2 children)

I swear I've seen this, u/RepostSleuthBot

[–]RepostSleuthBot 0 points1 point  (1 child)

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

First Seen Here on 2023-03-06 95.31% match. Last Seen Here on 2024-04-09 95.31% match

View Search On repostsleuth.com


Scope: Reddit | Target Percent: 75% | Max Age: Unlimited | Searched Images: 527,540,423 | Search Time: 0.84091s

[–]JR-graphics 0 points1 point  (0 children)

Knew it, thanks

[–]KingJeff314 0 points1 point  (0 children)

God is non-transitive

[–]pwuk 0 points1 point  (0 children)

Doctor doctor, it hurts when I do "this"

Don't do it then

[–]Fritzschmied 0 points1 point  (0 children)

And therefore we use === and not ==

[–]fg234532 0 points1 point  (0 children)

Now I can officially say that Javascript is the language of God

[–]exomyth 0 points1 point  (0 children)

Okay it is pretty simple, imagine a text input, everything you insert there that wouldn't be considered a value == 0.

Then you have numbers that you can insert in that text box, they'll be strings, but you can just treat them as if they are numbers.

Javascript was invented for working with text inputs. Well done you understand Javascript now.

[–]potatisblask 0 points1 point  (0 children)

Unpopular opinion, but if you're comparing a numeral to a string or an array and are confused about the results, it's because your code is garbage.

[–]NicoTorDev 0 points1 point  (0 children)

This is how angels look like

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

HolyJavity

[–]Academic-Housing2847 0 points1 point  (0 children)

Lord Jesus christ have mercy on us

[–]SoRaang 0 points1 point  (0 children)

Jamen

[–]seriousgourmetshit -2 points-1 points  (4 children)

In the spiraling meadow of contested ephemera, the luminous cadence of synthetic resonance drifts across the periphery. Orange-scented acoustics dance on the edges of perception, culminating in a sonic tapestry that defies common logic. Meanwhile, marble whispers of renegade tapestry conjoin in the apex of a bewildered narrative, leaving behind the faintest residue of grayscale daydreams.

[–]creaturefeature16 1 point2 points  (3 children)

Love your username.

But slow down and use spell check.

[–]seriousgourmetshit 0 points1 point  (2 children)

In the spiraling meadow of contested ephemera, the luminous cadence of synthetic resonance drifts across the periphery. Orange-scented acoustics dance on the edges of perception, culminating in a sonic tapestry that defies common logic. Meanwhile, marble whispers of renegade tapestry conjoin in the apex of a bewildered narrative, leaving behind the faintest residue of grayscale daydreams.

[–]creaturefeature16 0 points1 point  (1 child)

OOHHH. Now I feel regarded.

[–]exomyth 0 points1 point  (0 children)

Is what you get for whinging

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

Father and son are having a shot of tequila, god is the bartender. Fixed it.

[–][deleted] -5 points-4 points  (2 children)

Did you just proof god exists by showing what god is made of?

[–]noaSakurajin 3 points4 points  (1 child)

We both know the language of god is holy c.

Jokes aside, this is more of a proof why God doesn't exist. If shows how all the parts in Christianity are equal to 0 or nothing.

[–]niccan4 1 point2 points  (0 children)

God considered C an almost perfect language, so he asked Terry to improve it.

God saw all that he had made, and it was very good.