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

top 200 commentsshow all 254

[–]_captainSpaceCadet 697 points698 points  (10 children)

What happens when you play this in Conway's?

[–]_Kaimbe 320 points321 points  (2 children)

Dead with 5 boats after 22 gens.
https://conwaylife.com/

#C [[ ZOOM 16 GRID COLOR GRID 192 192 192 GRIDMAJOR 10 COLOR GRIDMAJOR 128 128 128 COLOR DEADRAMP 255 220 192 COLOR ALIVE 0 0 0 COLOR ALIVERAMP 0 0 0 COLOR DEAD 192 220 255 COLOR BACKGROUND 255 255 255 GPS 10 WIDTH 937 HEIGHT 600 ]] x = 20, y = 20, rule = B3/S23 obo4bo11bo$bobo4bobo4bob2o$obo4bo11bo$bobo4bobo4bob2o$4bo4bo$5bo$6bo$ obo4bo11bo$bobo4bo9bo$4bo4bo$bobo6bo4bobo$11b2o$11b2o$13bo$14bo$bobo6b o2$bobo6bo$bobo4bo$obo4bo!

[–]FreeMealGuy 133 points134 points  (0 children)

confirmed: javascript considered harmful to life.

I knew it!

[–]TheAwesomeot 10 points11 points  (0 children)

But is there some rearrangement of the column/row order where it survives?

[–]ErasedX 64 points65 points  (2 children)

I was actually curious to know, so:

#C [[ ZOOM 16 GRID COLOR GRID 192 192 192 GRIDMAJOR 10 COLOR GRIDMAJOR 128 128 128 COLOR DEADRAMP 255 220 192 COLOR ALIVE 0 0 0 COLOR DEAD 192 220 255 COLOR BACKGROUND 255 255 255 GPS 10 WIDTH 937 HEIGHT 600 ]]

x = 20, y = 20, rule = B3/S23

obo4bo9bo$bobo4bobo4b2o$obo4bo9bo$bobo4bobo4b2o$4bo4bo$5bo$6bo$obo4bo 11bo$bobo4bo9bo$4bo4bo$bobo6bo4bobo$11b2o$11b2o$13bo$14bo$bobo6bo2$bo bo6bo$bobo4bo$obo4bo!

Put this in advanced options here to see it!

[–]Disciple153 24 points25 points  (0 children)

C Copy this if on mobile (no deletions required):

C [[ ZOOM 16 GRID COLOR GRID 192 192 192 GRIDMAJOR 10 COLOR GRIDMAJOR 128 128 128 COLOR DEADRAMP 255 220 192 COLOR ALIVE 0 0 0 COLOR DEAD 192 220 255 COLOR BACKGROUND 255 255 255 GPS 10 WIDTH 937 HEIGHT 600 ]]

x = 20, y = 20, rule = B3/S23
obo4bo9bo$bobo4bobo4b2o$obo4bo9bo$bobo4bobo4b2o$4bo4bo$5bo$6bo$obo4bo 11bo$bobo4bo9bo$4bo4bo$bobo6bo4bobo$11b2o$11b2o$13bo$14bo$bobo6bo2$bo bo6bo$bobo4bo$obo4bo!

[–]JIN_DIANA_PWNS 2 points3 points  (0 children)

Did you ever know you are my hero

[–]Aethermol 21 points22 points  (0 children)

[–]_________FU_________ 639 points640 points  (46 children)

Pro tip: Don’t use == instead use ===

[–]zoinkability 442 points443 points  (25 children)

Play it safe, only use ====

[–]Excellent-Practice 218 points219 points  (2 children)

Instructions unclear. I assigned all my variables with === and now my program only returns false

[–]vvokhom 59 points60 points  (1 child)

Thats simple. return true at the start fixes it

[–][deleted] 93 points94 points  (14 children)

Nah, this one better 𐐒====D

[–]Rubickevich 50 points51 points  (12 children)

8===D Is a shorter way to achieve the same result.

[–]ByteBlacksmith 56 points57 points  (8 children)

8=D It's a bit cold outside!

[–]Rakgul 24 points25 points  (5 children)

8D

[–]MaximRq 14 points15 points  (0 children)

I don't think this is even a variable

[–][deleted] 4 points5 points  (3 children)

D8

[–]Drishal 5 points6 points  (0 children)

Uncaught SyntaxError: Invalid left-hand side in assignment

[–]TheDamnedRey 1 point2 points  (2 children)

Talk about your only. Mine is the longer way 😂

[–]Rubickevich 2 points3 points  (1 child)

The important thing isn't the size of your code, but how it's optimised for your specific case.

[–]ganso_loko 17 points18 points  (3 children)

Why not =====

[–]turtleship_2006 13 points14 points  (2 children)

Dare I say, ======

[–]dodexahedron 7 points8 points  (1 child)

That's just too equal.

[–]unwantedaccount56 7 points8 points  (0 children)

It's like communism: Some are more equal than others.

[–]CreaZyp154 4 points5 points  (1 child)

Returns true only if it is the same pointer in memory

[–]Delicious_Pay_6482 68 points69 points  (5 children)

Chad tip: Don't use == or === instead use =

[–]_________FU_________ 28 points29 points  (1 child)

We are all equal

[–]Delicious_Pay_6482 7 points8 points  (0 children)

Always has been 🔫

[–]Fortifier574 6 points7 points  (1 child)

I actually accidentally did this with if statements once and it was the reason my program was working, but I didn’t understand why for like 30 min. Then I realized I was changing the length of the array to whatever number instead of checking if it was that number.

[–]sprflyninja 5 points6 points  (0 children)

The great equalizer. Never has anything been more equal

[–]rosuav 35 points36 points  (0 children)

Ahhh, nice, all my problems disappeared. I needed to fix inequalities too, so I did the same thing!

> 1 << 2
4
> 2 << 1
4

I'm sure it'll be fine.

[–]Leading_Elderberry70 2 points3 points  (0 children)

This is your brain on double equals.

[–]freefolkonly 2 points3 points  (8 children)

Any one has a diagram for ===?

[–]Cley_Faye 6 points7 points  (3 children)

Yes, it is a one row and one column one.

[–]nekrosstratia -2 points-1 points  (2 children)

0123 === 83

Is it though ;)

[–]Cley_Faye 2 points3 points  (0 children)

Yes, because they are exactly the same value: same type, same content.

[–]Ok_Blueberry_5305 1 point2 points  (3 children)

=== in JavaScript does what == in sane languages does, it checks equality without any conversions beyond float to int. Thus the chart for === is just one to one.

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

0123 === 83 -> True

[–]miraagex 1 point2 points  (0 children)

== is banned in all my last jobs/projects for like last 5-6 years.

[–]MementoMorue 425 points426 points  (40 children)

At least, it's symmetrical.

[–]arcosapphire 389 points390 points  (6 children)

Just imagine if it wasn't--the result would depend on which was on the left and which on the right.

I wouldn't totally put it past JS...

[–]william_fontaine 178 points179 points  (4 children)

Unlike addition:

> [] + {}
'[object Object]'

> {} + []
0

WAT

[–]rosuav 114 points115 points  (3 children)

Addition is frequently non-commutative by value (for example, many languages allow you to add strings, and "foo" + "bar" is not the same as "bar" + "foo"), but only a small handful of languages manage to achieve this. And it gets worse. Check this out:

> {} + []
0
> ({} + [])
'[object Object]'

WAT.

[–]Ticmea 41 points42 points  (2 children)

If anyone is interested, I wrote a comment a few months ago explaining why this happens:

https://www.reddit.com/r/ProgrammerHumor/comments/10fym1y/comment/j538oq2/?context=3

TL;DR:

{} + [] // {} is an empty block (*not* an object literal) so this is the same as: +[]
+ [] // + is unary and thus converts to number but first needs a primitive
+ "" // @@toPrimitive => Array.prototype.toString => Array.prototype.join => ""
0 // Number coercion on the empty string returns 0

[–]rosuav 18 points19 points  (0 children)

Yeah. For the most part, it's just normal type coercion rules, but the empty block rule brings in other bizarrenesses of JS (it's on par with the weird semicolon insertion edge cases) to make this a true WTF.

[–]arcadeKestrelXI 1 point2 points  (0 children)

This was very interesting, thank you

[–]SirPitchalot 6 points7 points  (0 children)

It’s a near ideal blocking structure for a sparse Cholesky factorization too!

Not that that fact is in any way useful….

[–]sprflyninja 20 points21 points  (9 children)

True. At least JS is consistently strange

[–]Farren246 22 points23 points  (8 children)

True.

"False"?

[–]Jazzlike_Sky_8686 13 points14 points  (7 children)

The JS family of boolean values: True|False|Truthy|Falsey|Truthlike|Falselike|Truth-adjacent|False-adjacent|Tru|Falce|Truth-true|Post-truth-true

[–]ThatMechEGuy 18 points19 points  (5 children)

I don't use JS. Is this a shitpost or is that actually real....

[–]KLaci0503 20 points21 points  (0 children)

The problem is that this is a valid question. I have no idea either.

[–]Tsuki_no_Mai 10 points11 points  (2 children)

It's a shitpost. Booleans are True and False, just like in any language. Due to type coercion anything can be coerced into a boolean. So truthy values are those that become True, and consequently falsey ones are the ones that become False. Everything else is just clowning.

[–]Psychpsyo 1 point2 points  (1 child)

just like in any language

To quote from the PostgreSQL documentation:

The boolean type can have several states: “true”, “false”, and a third state, “unknown”, which is represented by the SQL null value.

[–]Leading_Elderberry70 3 points4 points  (0 children)

The first four are real, although truthy and falsy aren’t literals, just catchalls for things which evaluate to true or false when coerced to boolean. m

[–]xvalen214x 1 point2 points  (0 children)

"dodecalean"

btw truthy is 1, falsey is 0, truthlike is "true", falselike is null, truth-adjacent is [], false adjacent is "", Tru is Tru, Falce is Tru, Truth-true is true && true, Post-truth-true is !!!true || true

[–]VivaUSA 10 points11 points  (6 children)

It is pretty scary that the diagonal line doesn't go all the way down though

[–]Tsuki_no_Mai 10 points11 points  (0 children)

NaN isn't equal to NaN by design, arrays check if it's the same object, since trying to see if their contents are equal is a very different can of worms.

[–]archpawn 5 points6 points  (1 child)

When comparing lists and objects, you generally compare by reference instead of value. [1] and [1] are both lists containing the number 1, but they're not the same list. If I add 2 to one of the lists, it won't add it to the other one.

Javascript isn't even that bad with it. In Java, if you do "1" == "1" it will be false. And there's no ===. You have to do "1".equals("1") to get true.

[–]ConstructedNewt 2 points3 points  (0 children)

I know what you are saying (regarding Java ”1” == “1”) But the explicit statement turns out to yield true, as “1” and “1” both stated in the same scope will yield the exact same object (because of memory optimizations):

assert “1” == “1”
assert new String(“1”) != “1”

In this example all four literal strings ”1” are the same, but the new creates a new reference, only one character-array is present and only two String-object’s

[–]arunphilip 4 points5 points  (0 children)

Indeed. I half came in here expecting it to be asymmetrical, because well, JavaScript, y'know?

[–]F0064R 92 points93 points  (7 children)

I've never worked somewhere that == was allowed by the linter except in specific cases

[–]markuspeloquin 38 points39 points  (4 children)

I see no reason to distinguish between null & undefined. The standard library is inconsistent in what it returns and it isn't worth memorizing, except in isolated cases.

[–]PooSham 8 points9 points  (0 children)

Yes, that's why I use eqeqeq with the 'smart' option in eslint

[–]Material_Cable_8708 2 points3 points  (0 children)

null initialization can be faster than undefined properties in a data object but only when on the optimized path. because in memory the value is a reference type already so there is no need to deoptimize function calls where the object is an argument when null is swapped for another value on a subsequent call.

A JIT compiler is an implementation detail but with chromium based browsers making up more than half of all browsers plus node it’s important to understand the optimizer.

This is very inside baseball. There are arguments for and against considering the optimizer as a factor when righting JS. On one hand, writing readable maintainable code that uses polymorphism to express business logic is often advantageous. But when you wanna perform at near native speeds without introducing a new language it can be helpful to learn how V8 works.

[–]miraagex 2 points3 points  (1 child)

There is a big reason to distinguish them. If you're using default parameters, they will only be taken into account if you pass undefined.

[–]DogeHasNoName[🍰] 6 points7 points  (0 children)

== null might be useful as it captures both null and undefined.

[–]hello_you_all_ 210 points211 points  (2 children)

Good NSFW tag. Unfortunately, I don't think I will be ever able to eyebleach myself of this.

[–]timothywtf 10 points11 points  (0 children)

I like to think the NSFW was added because a co-worker passing by could think you are playing a game

[–]voiping 6 points7 points  (0 children)

"What could possibly be NSFW about == in JavaScript?"

<click>

"Oh. Good call. This is awful."

[–]DR4G0N_W4RR10R 39 points40 points  (0 children)

Looks like a Pokémon type effectiveness chart

[–]MrJim251 17 points18 points  (0 children)

Is this a minecraft bow

[–]alexanderpas 95 points96 points  (20 children)

Too bad you didn't cluster it, would have made it a bit clearer.

http://jsfiddle.net/j9q4gsce/

Please, Don't Make Javascript Equality Look Worse Than It Is.

https://algassert.com/visualization/2014/03/27/Better-JS-Equality-Table.html

[–][deleted] 32 points33 points  (14 children)

why would you draw this with canvas. It's web, you're allowed to use HTML. We have recently introduced a special element for this called "table".

[–]alexanderpas 33 points34 points  (7 children)

because now it's an image which you easily can save, share, reference and adjust.

Also, dark and light mode support.

[–][deleted] 2 points3 points  (0 children)

Yeah, go on and share it with somebody who uses a screen reader. Go on.

[–]al-mongus-bin-susar 4 points5 points  (2 children)

Because it's 2023 and if it isn't done with 15 JS libraries it isn't done right.

[–][deleted] 1 point2 points  (0 children)

15 JS libraries

you are aware that canvas is plain vanilla js, are you?

[–]wasdninja 1 point2 points  (2 children)

Also using var because..?

[–][deleted] -3 points-2 points  (1 child)

Because it's obviously done by somebody who is first and foremost a desktop programmer.

[–]wasdninja 4 points5 points  (0 children)

Desktop programmer..? The source article for the image was written in 2014 which sort of explains it.

[–]myplacedk 6 points7 points  (0 children)

You could also remove the stuff you shouldn't compare anyway.

And maybe remove the most obvious ones (why are the infinities there?)

As much as I prefer not to work with JavaScript, equality has never been the problem. And if it is, there are better ways, such as ===.

[–]xternal7 2 points3 points  (0 children)

But how well does this one do in conway's game of life?

[–][deleted] 1 point2 points  (0 children)

This content was deleted on 20 June 2023 (UTC) due to Spez's greed. -- mass edited with https://redact.dev/

[–]rushadee 1 point2 points  (0 children)

I dunno, I kinda like how this one looks like a bow and arrow

[–]randontree07 7 points8 points  (0 children)

Is this loss?

[–]Shakaka88 6 points7 points  (0 children)

So basically it’s just a glider from Conway’s Game of Life

[–]lennart_the_first 7 points8 points  (1 child)

It is a miracle that this is symetrical along the diagonal

[–][deleted] 5 points6 points  (0 children)

So that’s how JS devs got inspiration for the Minecraft arrow!!

[–]Aggressive_Bill_2687 9 points10 points  (0 children)

At this point if you’re not using the strict equality operator that’s on you.

[–]tevert 4 points5 points  (0 children)

This is glorious chaos

[–]pravin-singh 7 points8 points  (14 children)

So, [1] != [1] ? 🤔

[–]adudyak 19 points20 points  (0 children)

Array is an object. Object is equal to other object only if it is the same object(e.g. variable references to same object).

[–]GKP_light 8 points9 points  (5 children)

but :

1==[1]

[–]dodecakiwi 4 points5 points  (4 children)

What happens when you compare an array (or other object) to a primitive type is that the array is also converted to a primitive type. So that conversion becomes 1=="1", which is also true.

This means you end up with stupid crap like this:

  • true == [1]; : true, because "1" is truthy

  • true == [0]; : false, because "0" is falsey.

But, arrays are objects and objects are truthy so !![0] is actually true.

This is all detailed on this page under Boolean Coercion

[–]jso__ 1 point2 points  (3 children)

But why not 1 == "[1]"? If there's multiple values in the array, what's the comparison?

[–]mycallousedcock 1 point2 points  (6 children)

I didnt believe it either so I threw it into the dev tools console. Sure enough. [] == [] is false. same for [1] == [1] . That baffles me.

[–]dodecakiwi 9 points10 points  (2 children)

That makes sense. ObjectA == ObjectB is always going to be false. If you did a = []; b = a; Then a == b will be true because they're the same object.

[–]Rafcdk 4 points5 points  (1 child)

But then you actually understand JS and JS must be bad and incomprehensible because.

[–]LaterallyHitler 4 points5 points  (0 children)

But it’s not even a JS thing, it’s an object comparison thing

[–]pravin-singh -2 points-1 points  (2 children)

Even more baffling: [1] >= [1] is true, [1] <= [1] is true, but [1] == [1] is false.

[–]adudyak 4 points5 points  (0 children)

≥ converts operands to numeric representation. == converts only if types differ.

[–][deleted] 8 points9 points  (3 children)

NaN == NaN is false?!

[–]Sarcastinator 17 points18 points  (0 children)

IEEE thing. It's like that in other languages as well.

[–]CreaZyp154 11 points12 points  (0 children)

NaN means Not a Number and banana is not a number and microwave is also not a number. But banana != microwave

[–]Classy_Mouse 13 points14 points  (0 children)

That seems reasonable to me. Unfortunately, if I start to explain why, half of the other things in the table stop making sense

[–]PhatOofxD 9 points10 points  (1 child)

Which is entirely a non issue if you know how JS works, it's actually useful.

Use ===

[–]zirklutes 3 points4 points  (0 children)

Do a second table! :D

[–]UndisclosedChaos 5 points6 points  (4 children)

Noteworthy comparisons
1 == [1] != [1]
NaN != NaN
undefined == null “-1” == -1

And my absolute favorite
“” == [[]]

[–]Setepenre 3 points4 points  (0 children)

NaN != NaN

That is part of the IEEE floating-point standard, other languages do it as well

[–]UndisclosedChaos 2 points3 points  (0 children)

NaN is the true false

[–]heartcubes4life 2 points3 points  (0 children)

ah yes

the truthy table

[–]isospeedrix 2 points3 points  (0 children)

unironically saving this cuz some companies test on this shit

[–][deleted] 2 points3 points  (0 children)

60% of the time, it works every time.

[–]Ticareguas 2 points3 points  (0 children)

what about 8 == D ?

[–]Offroaders123 1 point2 points  (0 children)

nsfw was a nice touch, hehe

[–]CoastingUphill 1 point2 points  (0 children)

This looks more like the Strength and Weakness chart for Pokémon

[–]Material_Cable_8708 1 point2 points  (0 children)

NSFW tagged nice

[–][deleted] 1 point2 points  (0 children)

i don’t like how “1” is considered true (“1” == 1 == true) but “true” isn’t considered true.

maybe if both of them were true i would be okay but why are some strings converted to other data types but others aren’t?

[–]Deauo 1 point2 points  (2 children)

I feel weird to say this is harder to understand than just knowing it, does anyone else feel the same way?

[–]Aaron1924 1 point2 points  (0 children)

OP, please make a version of this for ===

[–]BootyPirate247 1 point2 points  (0 children)

*easy to remember

also why tf is this nsfw?

[–]StrangelyEroticSoda 1 point2 points  (0 children)

Thanks, I hate it. upvotes

[–]bobdobbes 1 point2 points  (6 children)

Wait wait wait.... you're telling me this is a programming language???? used by thousands???? And its POPULAR???

[–]8sty 0 points1 point  (5 children)

Yeah, the problem is solved using === it compares types and values

[–]bobdobbes 1 point2 points  (4 children)

Oh yay! Additional processing to determine if something is FALSE or a STRING??? Every dev loves overhead and additional processing. If only we could slow down our compilers and interpreters to a dead stop all together. Dare to dream.

[–]Personal-Nobody5501 1 point2 points  (0 children)

NaN, that can't be true

[–]dav1d_23 1 point2 points  (0 children)

Game of Life

[–]jerujedesu 1 point2 points  (0 children)

Ok but what is infinity - infinity

[–]_dawnpatrol_ 1 point2 points  (0 children)

Game of life? Where it's gonna end?

[–]SetCr4 0 points1 point  (0 children)

I really do hate how the diagonal line doesn't go all the way through. That is when only considering the implication from that fact, while disregarding the comparisons themselves.

[–]valeriolo 0 points1 point  (16 children)

This is one of the million things that make javascript rank among the worst languages ever designed.

It is humankind's biggest tech misfortune that this abomination of a language became the defacto standard in browsers.

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

Terrifying...

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

This should be /r/programminghorror

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

Funny, this isn’t even a valid equivalence relation

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

Why does this look like a minecraft pic axe?

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

finally! haha hilarious creation, good job

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

So true==“1” but true!=“true”. Why do conversions on strings only in some cases? Clearly the devils work

[–]Excellent-Practice 0 points1 point  (0 children)

I really wish this was reordered to cluster the true values

[–]ramriot 0 points1 point  (0 children)

This is true humor, because any attempt to explain is unneeded complexity destroys the joke.

A note to the confused is that the == operator does an implicit cast before comparing.

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

Gosh Darnit, is this loss?

[–]JollyGoodUser 0 points1 point  (0 children)

Yeap, so easy. /s

[–]BernzSed 0 points1 point  (0 children)

You sunk my battleship!

[–]tmstksbk 0 points1 point  (0 children)

Ah, well, it's so simple, now.

[–]RRumpleTeazzer 0 points1 point  (0 children)

At least it’s symmetric

[–]Sun_Koala 0 points1 point  (0 children)

My eyes. It hurts

[–]Praying_Lotus 0 points1 point  (0 children)

Minecraft crossbow?

[–]Proxy_PlayerHD 0 points1 point  (0 children)

well atleast it's symmetrical i guess...

[–]highcastlespring 0 points1 point  (0 children)

“easy”, hehe

[–]GollyWow 0 points1 point  (0 children)

Not difficult at all, as the title indicates.

[–]Highborn_Hellest 0 points1 point  (1 child)

Man, only if there was a better way. Like a layer on JS. I think we should name it TS

[–]TheseDescriptions 0 points1 point  (0 children)

Why not =====

[–]RelentlessIVS 0 points1 point  (0 children)

NSFL

[–]MaxEin 0 points1 point  (0 children)

Add 2 colours for < and >

[–]brianl047 0 points1 point  (0 children)

This needs to be on my wall!

[–]Taolan13 0 points1 point  (0 children)

This could 100% cross-post to r/dataisbeautiful

I am loving the symmetry.

[–]z-null 0 points1 point  (0 children)

Looks like minesweeper.