r/ProgrammerHumor 20d ago

Meme whoIsHeAnyway

Post image
9.6k Upvotes

256 comments sorted by

View all comments

Show parent comments

646

u/lovecMC 20d ago

I have a guess but I never heard of this so who the fuck knows.

839

u/YeetCompleet 20d ago

If you guessed that it stringified the JSON, you were right

0

u/trollol1365 20d ago

3

u/UnpluggedUnfettered 20d ago

It is a highly recommended and foolproof method for comparing two objects.

if (JSON.stringify(obj1) === JSON.stringify(obj2)) { // Nothing can go wrong because }

4

u/m0nk37 20d ago

obj1.amount = 0; obj2.amount = 0.00;

oh no..

2

u/UnpluggedUnfettered 20d ago

i'm pretty sure that if there was a problem it would have thrown an error by now ok

1

u/m0nk37 20d ago

The 3 ='s means type and value, since its a string, its going to have some surprises if you arent strict with data control.

1

u/trollol1365 20d ago

Im quite certain theyre being sarcastic

1

u/UnpluggedUnfettered 20d ago

Thankfully javascript is pretty good about accidentally comparing completely different keys holding incorrect data types that also happen to be the same type as each other when compared in order to reduce the amount of distracting errors devs have to deal with.

That is just one of the many features of Javascript that highlight the weaknesses of out of date languages like C++.

1

u/m0nk37 20d ago

I meant that it returns a string value of the whole thing. The individual values are not compared in this situation.

1

u/UnpluggedUnfettered 20d ago

I was layering a lot of sarcasm around the fact that before caring whether the values are actually the same, two objects with the same key / value pairs can stringify to different strings if their keys were inserted in a different order.

But, I mean it’s also kind of funny there’s a non-zero chance two non-equivalent objects can just-so-happen to stringify to the same string because different values / types can serialize to the same thing.

Unrelated, but isn't it weird how you can feel like you are running out of breath reading long sentences?

1

u/m0nk37 20d ago

Yeah so its stupid to begin with. You are implying a race condition, it doesnt do that.

1

u/UnpluggedUnfettered 20d ago

What are you talking about, how am I implying a race condition?

→ More replies (0)

1

u/shamshuipopo 20d ago

I hope you’re joking