r/ProgrammerHumor • • Mar 20 '24

Meme areJSDevsActuallySane

Post image
14k Upvotes

554 comments sorted by

3.1k

u/Ambitious-Finance-83 Mar 20 '24

can't wait for this to come up in an interview...

837

u/Confident-Ad5665 Mar 20 '24

If you're English you should know it doesn't work with "mum"

270

u/uday_it_is Mar 20 '24

But “pop” will work?

56

u/Exaskryz Mar 20 '24

So would jig, bip, freckles.

29

u/theunquenchedservant Mar 21 '24

are these things the british people call their parents?

→ More replies (8)

0

u/[deleted] Mar 20 '24

[deleted] — view deleted comment

30

u/the-liquidian Mar 20 '24

The square bracket is not typed, the {} object gets converted into a string representation which is [object Object]. These square brackets then have regex meaning, match anything inside of them. The o matches Mom, there is nothing in the brackets that match Dad.

103

u/iridescenttriangles Mar 20 '24

Yeah, you'd likely ((![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]).toUpperCase().

75

u/Trappist-1ball Mar 20 '24

for those who are wondering

((![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]).toUpperCase() // "FAIL"

50

u/[deleted] Mar 20 '24 edited Oct 20 '24

Despite having a 3 year old account with 150k comment Karma, Reddit has classified me as a 'Low' scoring contributor and that results in my comments being filtered out of my favorite subreddits.

So, I'm removing these poor contributions. I'm sorry if this was a comment that could have been useful for you.

43

u/iridescenttriangles Mar 20 '24

When you're used to JS it's as straightorward and natural as parseInt(Number.MIN_VALUE) being 5

31

u/[deleted] Mar 20 '24 edited Oct 20 '24

Despite having a 3 year old account with 150k comment Karma, Reddit has classified me as a 'Low' scoring contributor and that results in my comments being filtered out of my favorite subreddits.

So, I'm removing these poor contributions. I'm sorry if this was a comment that could have been useful for you.

33

u/iridescenttriangles Mar 20 '24

parseInt with arity 1 interprets its argument as a string representing a base-ten int and stops parsing when it encounters the first character that doesn't make sense for that. Numbers are doubles/float64s, Number.MIN_VALUE gives you the smallest positive value representable by that which is 5e-324. parseInt stops parsing that with the e.

parseInt with arity 2 takes the base as the second argument, you can do convenient things like parseInt(parseInt, 35) which is 1021464698788.

→ More replies (9)

11

u/JonDum Mar 21 '24

That's actually super impressive that it can break it down and analyze it like that...

It's equally hilarious that it still got it wrong.

19

u/OliviaPG1 Mar 21 '24

Because it’s not breaking down and analyzing it. It’s just producing text that looks as similar as possible to what text of someone breaking it down and analyzing it would look like.

10

u/Disastrous-Team-6431 Mar 21 '24

The best formulation of this concept ive heard. It's insane that "producing text that looks like code that does what you asked" or "producing text that looks like debugging your code" will do those things.

→ More replies (1)
→ More replies (7)
→ More replies (3)

2

u/cat_91 Mar 21 '24

Play with this yourself: https://jsfuck.com/

→ More replies (2)
→ More replies (1)

34

u/al-mongus-bin-susar Mar 20 '24

This isn't useful in any situation except shitposts and some old type checking code so probably not.

19

u/[deleted] Mar 20 '24

I think they were joking.

→ More replies (4)

1

u/Average-Fellow Mar 20 '24

Typescript error

1

u/andouconfectionery Mar 21 '24

To allow this code to touch a runtime is to scorn God's gift of tsc. The output of this program is eternal damnation. Let's talk salary.

1.2k

u/Spot_the_fox Mar 20 '24

Huh, neat

979

u/PeriodicSentenceBot Mar 20 '24

Congratulations! Your comment can be spelled using the elements of the periodic table:

H U H Ne At


I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM my creator if I made a mistake.

632

u/Spot_the_fox Mar 20 '24

Huh, neat. Good bot. 

160

u/[deleted] Mar 20 '24

I like your energy.

14

u/swishbothways Mar 21 '24

O H F U C K O F F

(let's see if the bot catches it. 🤞)

→ More replies (1)

43

u/SYNTAG Mar 20 '24

So many neat things all at once

3

u/HelioDex Mar 21 '24

Oh no not again

3

u/Spot_the_fox Mar 21 '24

What, not again? eh?

P.s:

O H N O N O Ta Ga In

63

u/qoheletal Mar 20 '24

Very specific bot

51

u/Antrikshy Mar 20 '24

It's even more specific than the "all your words are in alphabetical order" or "your comment as a haiku" bots!

55

u/Gluomme Mar 20 '24

You forgot "your comment as a haiku which is actually off by one syllable but it's ok because there's this obscure joke in Avatar The Last Airbender where one of the main character does the same thing"

→ More replies (2)

15

u/[deleted] Mar 20 '24

I like the one 3 that checks to see if all the 46 numbers in your post add up 20 to sixty nine, let's see if it works here

6

u/unipleb Mar 20 '24

Now I'm wondering if it's possible to check if a string matches elements in the periodic table using one big regex

→ More replies (2)
→ More replies (3)
→ More replies (2)
→ More replies (5)

829

u/Kashrul Mar 20 '24 edited Mar 20 '24

I know nothing about js, maybe that's why I can't see square brackets in initial question?

938

u/FedExterminator Mar 20 '24

The square brackets are in the conversion to the string ‘[object Object]’

719

u/_Foy Mar 20 '24

That's what's really wild about this whole thing

318

u/Antrikshy Mar 20 '24

The wildest part is that new RegExp doesn't fail when given an object.

172

u/Some-Guy-Online Mar 20 '24

I can excuse a lot of things in JS because of its origin and the efforts to maintain backward compatibility.

But I can't see any justification for new RegExp to indiscriminately coerce any input to a string.

It should either be a string already or a regex literal.

→ More replies (48)
→ More replies (27)
→ More replies (3)

28

u/djliquidice Mar 20 '24

Thank you.

15

u/LumiWisp Mar 20 '24

How did we allow this language into the core of WebDev?

4

u/AspiringMILF Mar 20 '24

ah. 'mom' isn't the pattern, it's the test

7

u/Dhelio Mar 20 '24

Holy fuck, is js for real?!? And I've even seen people say that js is a totally viable backend language. Not with that bullshit, it isn't!

13

u/al-mongus-bin-susar Mar 20 '24

Why do you think implicit type conversation means that it isn't a viable backend language?

→ More replies (4)
→ More replies (2)

18

u/_1Zen_ Mar 20 '24

object Object is inside square brackets

2

u/SadPie9474 Mar 20 '24

did you see line #1 in the explanation?

0

u/[deleted] Mar 20 '24

[deleted] — view deleted comment

10

u/badmonkey0001 Red security clearance Mar 21 '24

wants a string, not an object

Strings are objects in JS. Try this on a console:

"foobar".constructor
// ƒ String() { [native code] }

True, it could check the type of object but obviously it doesn't.

→ More replies (4)
→ More replies (4)

184

u/PM_ME_YOUR__INIT__ Mar 20 '24

Screenshot of a repost of a reddit post from yesterday? https://www.reddit.com/r/ProgrammerHumor/s/pJRAv69CZ5

65

u/[deleted] Mar 20 '24

This post has the explanation inside it so that's nice

36

u/ProgramTheWorld Mar 20 '24

It’s reposts all the way down

8

u/[deleted] Mar 20 '24

I've seen this comment before

10

u/Strict_Treat2884 Mar 21 '24 edited Mar 21 '24

Kinda bizarre to see a Reddit post of a screenshot of a twitter post about my Reddit post got on #1 hot of the same subreddit where I originally posted.

3

u/BuckRowdy Mar 20 '24

It looks like a run-of-the-mill repost and not one of those insipid copybots.

1

u/Independent-Gear-700 Mar 20 '24

Yeah, this sub sucks

47

u/SoRaang Mar 20 '24

There's nothing console.log() can't handle

70

u/FrumpyPhoenix Mar 20 '24

Thanks, I hate it

19

u/NatoBoram Mar 20 '24

Can't unhear Fireship's pronunciation of [object Object]

3

u/Tc14Hd Mar 20 '24

How does he pronounce it?

8

u/NatoBoram Mar 20 '24

4

u/Tc14Hd Mar 20 '24

Fireship AI voice will take all of our jobs soon

2

u/Darkoplax Mar 26 '24

object object object object

2

u/CST1230 Apr 07 '24

[objecObjecobjecObject]

25

u/R4XD3G Mar 20 '24

Well, the issue is they forgot JSON.stringify()

19

u/Terewawa Mar 20 '24

The issue is that en object when cast to string would produce a descriptive string such as "[Object object]" which would only make sense inside a printing / logging / debugging function.

→ More replies (2)

13

u/[deleted] Mar 20 '24

Eh, you can do something silly with any language if you try

In c++ you can say

++++--++x

but you can't say

x++++

Not sure why you'd ever want to, but if we're doing RegExp({}), why not code something else stupid

6

u/pceimpulsive Mar 21 '24

Js is cracked mate... Wtf

89

u/Leonhart93 Mar 20 '24

This is the n-th post I see about accidental object to string conversions, while in like 10y of writing a ton of JS with various frameworks it happened by accident around...3 times. This underlines very clearly how humans are in general, they get obsessed and stuck on the most minor things that appear unusable or something at first glance, and then keep beating that dead horse.

69

u/FedExterminator Mar 20 '24

I see what you’re saying, and this example is clearly made to highlight an extreme case, but wouldn’t the language be better if it didn’t do weird object conversions like this?

I see the argument a lot that while writing JS you don’t often encounter these language quirks as long as you structure your code well, but I tend to stand behind the idea that it would’ve been better for the language to not allow you to do these things in the first place.

26

u/sammy-taylor Mar 20 '24

JavaScript is a great language but it has parts of the spec that were really quirky decisions. Unfortunately, things like conversion to [object Object] are indeed specified behavior, not undefined behavior, and are therefore unlikely to ever change. So we just have to live with this stuff now. But as the previous commenter mentioned, in my 7 years of writing JS I’ve been tripped up by zany type conversions only maybe 3 or 4 times. Not a prevalent problem for most JS devs.

→ More replies (38)

6

u/kimtaengsshi9 Mar 20 '24

It's the same situation for JS and Python. JavaScript was originally intended for simple scripting for webpages, in earlier times when we couldn't imagine just how powerful 21st century websites would become, while Python was intended to be simple. Strict typing was either considered unnecessary or undesired. It was a conscious design choice, and back then the concept of good programming practices and engineering wasn't very mature yet.

Fast forward to today, and strict typing is more important than ever for good code and such. NodeJS and Python are among the world's most popular languages now, however since typing wasn't originally part off the language's design, they've to retrofit and introduce it in a roundabout way which won't break legacy code.

In other words, JS does weird stuff like this because of old design decisions. It's always legacy, legacy, legacy.

2

u/sofaRadiator Mar 21 '24

At least Microsoft got some of the best language developers in the world for TypeScript, and though it does have a few rough edges, overall they’ve done an astonishing job rationalizing the insanity we started with. 

Python’s typing is still… really not great. 

Better than Ruby’s, though. Urg. 

→ More replies (1)

2

u/vlakreeh Mar 20 '24

but I tend to stand behind the idea that it would’ve been better for the language to not allow you to do these things in the first place.

Oh definitely, but I think that's become the overall consensus within the JS ecosystem now that nearly everyone writes primarily TypeScript.

2

u/sofaRadiator Mar 21 '24

Yes, people shouldn’t make excuses for stupid behaviour like this. But at least if you look at any APIs added to the platform in the last five or ten years, they throw errors like you’d hope a sane language would. And any responsible developer these days will be using typescript and avoid 99% of these issues ahead of time. It’s a pretty good experience if you’re using modern tools, but the legacy baggage is going to be with us forever. 

→ More replies (7)
→ More replies (4)

30

u/MeltedChocolate24 Mar 20 '24

Just use typescript this is 2024 not the 90s

3

u/al-mongus-bin-susar Mar 20 '24

Typescript is great but it gets cumbersome because it really puts an accent on the types more than every other language out there. You have to litter every file with dozens of imports for every type you use, which makes decoupling harder. You end up almost having to write your application code twice, once in type logic and once in actual logic. Once you start doing something with any meaningful degree of complexity the type mess that naturally arises is more silly than C++ templates.

6

u/jasie3k Mar 21 '24

I fail to understand how types by themselves force to write logic twice.

→ More replies (2)

4

u/lazercheesecake Mar 20 '24

That tile on the floor is actually lava, but only that one, I’ve only lost three guests to it, I don’t know why people keep complaining about it, just step around it, not that hard

Or we could use a contractor that doesn’t just have a lava tile on the floor, or at least puts up a fence so people don’t just fall in

7

u/Leonhart93 Mar 20 '24

Heh, that's one way of framing to make something appear more important, when I just said it's basically irrelevant to me, I barely noticed it's a case that exists.

→ More replies (1)

1

u/cs-brydev Mar 20 '24

Or of the 30 total interesting things to even post about Javascript, 28 or them are unexpected type conversions. So what do you expect exactly from a Javascript post? Sheer boredom? Would that make you happier?

→ More replies (1)

5

u/KSP_HarvesteR Mar 21 '24

The explanation just made it more horrifying

13

u/Rest-That Mar 20 '24

I hate that this makes sense

9

u/6tPTrxYAHwnH9KDv Mar 20 '24

I see parts like this and think to myself "how neat!" And then I remember that this is not fucking normal.

3

u/Lazarus_Octern Mar 20 '24

I like that there is always some actual reason why jank like this exists but i dont like that it exists at all....

3

u/[deleted] Mar 20 '24

Every time I read (object Object) i read it in the voice of driods from star wars.

3

u/FromZeroToLegend Mar 20 '24

People complain about Js with examples that you’d never use in real life

3

u/CringyDabBoi6969 Mar 21 '24

guys please implicit conversions are good no they're useful because they uhh.... you dont have to write them out yourself they just happen and that will save you time, no please just.... its... you dont have to write anything tho its just does that... no you can know when but, no wait guys come back its saves time i swear guys please its helpful please!

5

u/wishper77 Mar 21 '24

In Italian 'mom'='mamma' and 'dad'='papà' Both will lead to false

So Js is not broken. English is

/s

7

u/TracerBulletX Mar 20 '24

Almost every "weird" thing is just a contrived example of type coercion and if you know how it works it makes sense even if you may not like it and prefer stronger types. And it never really comes up once you know JS because you just know what types things expect and sort of mentally do your own type checking.

2

u/Frown1044 Mar 21 '24

Type coercion actually makes sense here, just not in every single context.

In JS you can write code like new RegExp(/abcdef/g). The regex inside is an object, not a string. It can get converted to its equivalent string "/abcdefg/g" however.

Likewise other things that implement .toString() can return valid input.

8

u/CirnoIzumi Mar 20 '24

what a robust language, lets build servers and apps in it

13

u/DeathUriel Mar 20 '24

Oh right, let's code the weirdest thing. Like give an object to a regex check and expect something that automatically makes sense instead of you know, coding code that has any real use.

Sorry, I meant... JS BAD, BOOOO!

2

u/deprecateddeveloper Mar 20 '24

And while I agree with people that the language probably shouldn't even allow a lot of the weird shit we see with JS, that doesn't make it humor. Like ok not a great language design but how is it funny especially when there's an explanation in the OP. I write Rust, Go, Java, and JS and I've never in 20yrs+ of programming needed to write such weird obscure shit. At this point JS posts like this should be considered low effort and removed.

→ More replies (5)

4

u/AdvanceAdvance Mar 20 '24

Sigh, boring.

Yes, JavaScript cannot seriously be run with a linter. Pick your favorite: jshint, jslint, eslint, or entirely over to TypeScript. It's a little like the hundreds of tricky C puzzles solved by adding parenthesis in the correct place.

And yet, I still need separate build tools and package managers and deployment managers and cloud managers to print "hello, world".

2

u/wutzebaer Mar 20 '24

That's why you use typescript

2

u/[deleted] Mar 20 '24

2

u/sebbdk Mar 20 '24

Why would you do that?

2

u/Silly_Guidance_8871 Mar 20 '24

I don't like being reminded that PHP is the more sane of my 2 day-driver languages, thank you very much.

2

u/eitland Mar 21 '24

I have for years now said that the difference between Java and Javascript is about the same as the difference between an ordinary bike and a one wheel bike.

Javascript is slightly more lightweight. It has no other technical advantage.

No offense to the Javascript developers: it makes what you do much more impressive. 

I am also humble enough to admit that I am fairly sure I would not have been able to make a better language in three weeks myself.

But no way it is allowed in any of my projects now that TypeScript exists.

2

u/Honeybadger2198 Mar 21 '24

Browsers are fault-tolerant to a fault.

2

u/blindada Mar 21 '24

I'll never understand how a literal deathtrap turned into code became so widespread, especially in education. It is like handing gunpowder and shells to new recruits right off the bat...

2

u/AreaExact7824 Mar 21 '24

Wtf. Just keep away with js

2

u/LegenDrags Mar 21 '24

I fucking love javascript

2

u/Bagel42 Mar 21 '24

This is why typescript was invented

2

u/Modo44 Mar 21 '24

Every time I see JS-related shenanigans, I am more in awe of any of my browser-based services working, like, at all.

2

u/masterKick440 Mar 21 '24

I'm not sure that explanation made it any better.

2

u/Ri0ee Mar 21 '24

99% of JS memes are just "garbage in - garbage out" code and even explaining it does not change the fact

2

u/Lopsided_Afternoon41 Mar 21 '24

I feel as though I'd have picked up programming a lot quicker, had I not started with JavaScript.

2

u/Penguinmanereikel Mar 21 '24

{} gets converted to '[object Object]' by JS

Makes sense, but I still want to kill it.

2

u/ComposerTraining Mar 21 '24

Mom's an object...

6

u/subject_deleted Mar 20 '24

I get it... JavaScript dumb... But who would EVER try to do this? How could this possibly cause an issue for anyone who has the vaguest sense of what they're doing?

6

u/[deleted] Mar 20 '24

[removed] — view removed comment

3

u/subject_deleted Mar 20 '24

When you test your regex and it doesn't work... That's how you know it's broken and you need to debug it.

It's crazy that people don't shit all over other languages that have generic errors like "seg fault".. sometimes people do things so silly that there's no explicit error message. That's not a fault of the language.

3

u/SoInsightful Mar 21 '24

When you test your regex and it doesn't work... That's how you know it's broken and you need to debug it.

Dude, I hate "JS bad because I did silly thing" criticisms as much as the next person, but "just fix your regex when you finally notice it's randomly failing for no reason" is not a good defense of the language.

sometimes people do things so silly that there's no explicit error message. That's not a fault of the language.

That's absolutely a fault of the language. What else would it be?

→ More replies (5)
→ More replies (18)
→ More replies (5)

4

u/wildjokers Mar 20 '24

But there are no square brackets in those lines of code. So his point 2 doesn't make sense.

18

u/Lumethys Mar 20 '24

new RegExp({})

      |

      ↓

new RegExp([object Object])

      |

      ↓

new RegExp('[object Object]')

5

u/AbsolutelyFreee Mar 20 '24

This is fucking absurd

10

u/Cley_Faye Mar 20 '24

The middle step is wrong. {} is directly converted to a string with {}.toString(), which indeed results in [object Object]. Writing new RegExp([object Object]) is incorrect.

13

u/Lumethys Mar 20 '24

It is like a thought flow, not a compiling step. Or else I would just write the whole OP post back

3

u/ProgramTheWorld Mar 20 '24

The brackets come from the toString call of an object.

→ More replies (1)

2

u/[deleted] Mar 20 '24

No were not :3

2

u/TheMoonMoth Mar 20 '24

Hey I'm a JS Dev. The answer is no.

2

u/gangze_ Mar 20 '24

No, and I question my carreer path every day :)

2

u/kingottacYT Mar 20 '24

am js dev, can confirm i am not sane

2

u/GoodEfficiency8472 Mar 20 '24

I know nothing about JavaScript, perhaps that's why I can't see square brackets in the initial question?

3

u/Andersmith Mar 20 '24

as always with these posts, the secret is implicit type coercion. {} converted to a string is "[object Object]". Regex expects a string. JS makes sure it gets one by feeding the console log representation of whatever garbage non-string data you gave it.

1

u/damned_truths Mar 20 '24

That's what I thought initially, but I think they come from the "[object Object]" part.

2

u/anonymous_sentinelae Mar 20 '24

Once again, yet another JS truth table, crying about a stupid scenario clearly specified, serving as platform for juniors trying to look like they know something.

2

u/No-Con-2790 Mar 20 '24

That explains the how but not the why! Why would anyone think this is a good idea.

4

u/AdvanceAdvance Mar 20 '24

Because the designer had to shove something out the door in a hurry.

The language was relegated to minor tweak scripts for a decade until Douglas Crockford published "Javascript: The Good Parts" and made a language that was good enough to write client side code. Since then, it has made simple evolvutions for a decade to become the ECMA Script we use today.

There is an insane amount of backward compatibility, so a script saying "a == b" can rely on arcane conversion rules, though every build environment will scream about it.

1

u/djurze Mar 20 '24

I think it's worth keeping in mind if just wanted a regex in JS you'd use literal notation:

const re = /ab+c/i;

And using new Regexp() is something you'd use for dynamic expressions. Could it be better, obviously, but you have to try to actually replicate the result in the post. There's plenty of worse things to worry about, even with Regular expressions, if you don't pass an argument to .test() it'll search for "undefined" so RegExp({}).test() is true and RegExp("mom").test() is false

→ More replies (2)

2

u/1Dr490n Mar 20 '24

I’m not sure what I hate more about this code: the result or that it’s called RegExp instead of Regex

4

u/Raunhofer Mar 20 '24

Because it is short for Regular Expression? Why would one take three letters of the first word and two of the latter? What kind of madman are you?

3

u/HappyVlane Mar 20 '24

Have you ever heard anyone say "Regexp" in real life? It's either "Regex" or "Regular expression".

→ More replies (2)
→ More replies (2)

2

u/alterNERDtive Mar 20 '24

Whenever you think JS can’t possibly be even worse than you already think, something like this comes along.

1

u/Tc14Hd Mar 20 '24

If you want things to get even worse, look at this (if you don't already know the result):

Array(50).fill(Infinity).map(parseInt)
→ More replies (2)

1

u/neriad200 Mar 20 '24

a small part of my soul has surely died.. this shit-tier language can't really be what's holding up most web pages today, can it?

1

u/Specialist-Tiger-467 Mar 20 '24

No we are not. And that's why we are dangerous.

1

u/SarcasmsDefault Mar 20 '24

This court has found you are… not the ‘dad’, but you are the ‘father’

1

u/ilmk9396 Mar 20 '24

this is hilarious

1

u/emetcalf Mar 20 '24

"working as intended"

1

u/Acceptable-Tomato392 Mar 20 '24

As a JS dev, I can certify that we are most definitely not.

1

u/thatmaynardguy Mar 20 '24

Yes... and no... and nan....

1

u/fzzzzzzzzzzd Mar 20 '24

Sane devs know about well documented javascript features, and that javascript has quirks. :)

1

u/an_agreeing_dothraki Mar 20 '24

no. you can't trust them. they're all insane. The console told me so, but it was also in on it.

That's why I do all my debugging with alert() commands.
Means the government can't getcha

1

u/breischl Mar 20 '24

Next time I get annoyed about having to manually call .toString() in Java, I'm going to remember this.

1

u/Semper_5olus Mar 20 '24

I gotta stop telling potential employers I can use JavaScript.

JavaScript makes no sense.

1

u/[deleted] Mar 20 '24 edited Mar 20 '24

Yes, we are sane, but it's a different kind of sane, unrecognizable as such by anyone with normal thought processes.

And that is itself exactly the sort of thinking that makes the way JS behaves comprehensible to us.

Go figure.

Edit: You should try native Clipper. Not only is everything a 'var', it has both lexical and dynamic scoping. You can do anything in the language, and almost all of it is wrong.

1

u/Tc14Hd Mar 20 '24

Here is my own version:

console.log(new RegExp({} + {}).test("boobs"));
console.log(new RegExp({} + {}).test("tits"));

Which outputs:

true
false

1

u/exmachinalibertas Mar 20 '24

javascript is such a fucking trainwreck I don't understand how it remains popular when other things like burning yourself alive exist as alternatives

1

u/Cody6781 Mar 20 '24

Omg guys why I use stuff in ways it was never meant to be used funny stuff happens omg guys look look

1

u/MajorTechnology8827 Mar 20 '24

Remember people, when Javascript expect a string, it will convert whatever in front of it to a string. Every object inherit tostring (its a property of object) , therefore every object behave as a string. Its a consistent behavior

If you learn how the prototype system of JS work, it is really intuitive

1

u/SaliferousStudios Mar 20 '24

oh javascript.

1

u/[deleted] Mar 20 '24

It’s fine as long as you understand the quirks of JS.

1

u/wonkey_monkey Mar 20 '24

I feel like that maybe kind of explains it but it doesn't really explain it...

1

u/Naliwe Mar 20 '24

Huh, perfect, can you bundle it in a npm package ? I need a 'isMom' function

1

u/BruceJi Mar 21 '24

I feel like JS is legacy code itself

1

u/Substantial-Mango499 Mar 21 '24

i need some help, where's the [] square brackets?

1

u/lostBoyzLeader Mar 21 '24

That’s fucking hilarious

1

u/1984isAMidlifeCrisis Mar 21 '24

If you debug it, you can see it.

1

u/Erizo69 Mar 21 '24

holy shit

1

u/DmC8pR2kZLzdCQZu3v Mar 21 '24

What a nightmare :(

1

u/Hidesuru Mar 21 '24

Any language that isn't strongly typed is weird to me lol.

1

u/RevealingPanda Mar 21 '24

Oh, I thought it matches with object because women are objects.

1

u/bikemandan Mar 21 '24

{} turns into a string?? wtf

1

u/Treriri Mar 21 '24

Only when the function expects a string, if it expected an object would have stayed an object

1

u/[deleted] Mar 21 '24

Every WTFJS post is a lesson in static typing

1

u/TuVeuxBaiser Mar 21 '24

Wait, so every time {} is used it brings in what would be an object except its always just a string that says object?

I mean, this seems insane... what am I missing? What is the use case for a string that says object Object that is in no way an object?

1

u/reddit_is_meh Mar 21 '24

This is just the default object to string cast behaviour of an object in JS, it returns The string [Object object]

It's not something you ever really do or use

→ More replies (1)

1

u/revolutionPanda Mar 21 '24

I see stuff like this all the time and people flex about knowing the answer. But wouldn't nothing like this ever come up in a real situation?

1

u/J4m3s__W4tt Mar 21 '24

It's almost like JS was designed to quickly hack together 100 lines basic interactive functions for websites and not for running actual applications.

1

u/vimescarrot Mar 21 '24

As someone who's tried to learn programming, this looks exactly like anything I tried to learn!

1

u/LustyHasturSejanus Mar 21 '24

Python devs acting smug when they get a runtime type error.

1

u/P0pu1arBr0ws3r Mar 21 '24

See? JS makes sense. Even though it's typeless, just assume it'll convert to some relevant type when something doesn't make sense and there's no error. This is essentially (quite literally) the to string method, so if other languages function fine with such then JS can too

1

u/Renard_Fou Mar 21 '24

Square brackets ? I dont see any...

1

u/Treriri Mar 21 '24

The square brackets are inside the text {} gets converted into, the “[object Object]”

1

u/[deleted] Mar 21 '24

You see what happens larry, this is what happens when you automatize type conversion !

1

u/wise_chain_124737282 Mar 21 '24

Js so bad its meme tops ProgrammersHumor thread daily ☠️

1

u/whackamattus Mar 21 '24

Lol no it doesn't need a default just throw a type error

1

u/GaraBlacktail Mar 21 '24

Am I blind?

I see no square brackets, so how does that work??

1

u/error_98 Mar 21 '24

Honestly the fact that anyone defends using a language employing this much secret under-the-hood magic in anything but a prototyping role terrifies me.

Like how tf is anyone supposed to find a bug caused by this interaction in a program bigger than 10 lines?

1

u/Dragonfire555 Mar 21 '24

One thing you could do is just... you know... avoid implicit conversions unless you know what you're doing. I avoid == like the plague and I make sure to know what's truthy and falsely. Oh, and use typescript.

1

u/x39- Mar 21 '24

Javascript is cursed and no sane person should ever use it

Which is why I am still baffled that there are pleb out there using js for backend development

1

u/TenYearsOfLurking Mar 21 '24

JS is smart as {} looks like... well, a mom

1

u/CaitaXD Mar 21 '24

mum & pops > mom & dad

1

u/molx730 Mar 21 '24

I feel like a lot of posts here are posted by people who may be coders but don't understand like syntax and how different languages interperate things. I am by no means against JS and understand it's weaknesses but every language has its place.

1

u/Linuxfan-270 Mar 23 '24

Even JS hates JS:

```

console.log(new RegExp({}).test('JavascriptIsBad'));

console.log(new RegExp({}).test('PlainHTMLIsBad'));

```

1

u/VergilSpardaa Mar 20 '24

{} = mom = women = object?

1

u/OnceMoreAndAgain Mar 20 '24 edited Mar 20 '24

I don't get why JavaScript wasn't changed years ago to not do all this overloading. The RegExp() function should only accept strings... Why would someone want to input something other than a string into the RegExp() function? If you want to do regular expressions on strings that reside inside some other data type (e.g. array), then make a new function that makes use RegExp() and give this new function a proper name to reflect what it does...

When is this overloading shit helpful? There's no way the pros benefit the cons. It just creates problems and solves nothing.

3

u/ineternet Mar 20 '24

The actual issue is that there is NOT an overload that takes an object. The object is coerced into a string BECAUSE the method can't handle accepting objects.

→ More replies (1)

1

u/TDR-Java Mar 21 '24

And that’s why this language should not be taken seriously. This is just bullshit behavior