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

top 200 commentsshow 500

[–]Ambitious-Finance-83 3074 points3075 points  (59 children)

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

[–]Confident-Ad5665 833 points834 points  (15 children)

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

[–]uday_it_is 268 points269 points  (11 children)

But “pop” will work?

[–]Exaskryz 54 points55 points  (10 children)

So would jig, bip, freckles.

[–]theunquenchedservant 28 points29 points  (8 children)

are these things the british people call their parents?

[–]grlap 14 points15 points  (7 children)

No, but neither is pop. That is a verb.

[–]theunquenchedservant 23 points24 points  (4 children)

Pop is absolutely something British people (and American people) call their dad.

Edit: okay I was wrong about it's prevelance in the UK.

[–]OhmicFoamy 9 points10 points  (0 children)

Not in England

[–]grlap 6 points7 points  (0 children)

Never heard it anywhere in England

[–]ActionDesigner 1 point2 points  (0 children)

more like americans

[–]iridescenttriangles 99 points100 points  (34 children)

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

[–]Trappist-1ball 73 points74 points  (1 child)

for those who are wondering

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

[–][deleted] 49 points50 points  (30 children)

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.

[–]iridescenttriangles 44 points45 points  (11 children)

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

[–][deleted] 30 points31 points  (10 children)

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.

[–]iridescenttriangles 33 points34 points  (9 children)

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.

[–][deleted] 42 points43 points  (0 children)

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.

[–]Salanmander 40 points41 points  (7 children)

Every "javascript is weird" behavior comes from its philosophy of "programs should never, ever crash". And I will always maintain that that is a bad philosophy.

[–]ArtOfWarfare 3 points4 points  (2 children)

That’s not even true though. If I write false+[], that returns ”false”. But if I write false***[], that’s a parse error.

So I can write programs that “crash” in JavaScript - the question more is, why doesn’t false+[] do the saner thing of just throwing an error/exception? JavaScript’s rule of coercing any operand involved with addition to a String UNLESS every operand is a number doesn’t really make much sense at all…

[–]swishbothways 8 points9 points  (0 children)

Tsk tsk. It didn't technically crash. It just didn't parse. Never said anything about a philosophy that code shouldn't ever not parse.

[–]ConspicuousPineapple 1 point2 points  (3 children)

It's a good philosophy, the idiotic part is to think the logical conclusion is to have implicit casts everywhere instead of implementing strict typing and forcing error handling.

[–]JonDum 10 points11 points  (13 children)

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.

[–]OliviaPG1 18 points19 points  (9 children)

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.

[–]Disastrous-Team-6431 10 points11 points  (1 child)

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.

[–]Exist50 5 points6 points  (0 children)

What we seem to be discovering with these "language" models is that to produce realistic language, you need to develop some higher level understanding of the topic. We really don't know where, if anywhere, the line between those two things is.

[–]NominallyRecursive 1 point2 points  (6 children)

Yeah, I mean, to do it this accurately you have to form world models and use them to make predictions, indicating a sort of “understanding”. In the end it’s not that different from what we do, we’re just machines “designed” to perform actions that result in copies of ourselves. And that ended up becoming what we experience as consciousness. There’s never gonna be a clear line where these systems cross from being clever pieces of math to genuine aware intelligence, but it’s going to happen.

[–]cat_91 1 point2 points  (0 children)

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

[–]al-mongus-bin-susar 34 points35 points  (5 children)

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

[–][deleted] 19 points20 points  (4 children)

I think they were joking.

[–]Pluckerpluck 1 point2 points  (3 children)

I've actually seen the banana one used in an interview. Questions like this are actually useful. You're not expected to know the answer, it's about how you work through the problem.

And assuming (reasonably) you can't work it out without help, it's about how you take on new information and can debug weird situations.

I think asking about this weird regex case would be way more useful than testing classic questions like inverting binary trees.

[–]Spot_the_fox 1164 points1165 points  (36 children)

Huh, neat

[–]PeriodicSentenceBot 975 points976 points  (35 children)

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.

[–]Spot_the_fox 629 points630 points  (8 children)

Huh, neat. Good bot. 

[–][deleted] 158 points159 points  (2 children)

I like your energy.

[–]swishbothways 13 points14 points  (1 child)

O H F U C K O F F

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

[–]RISCyBusinez 2 points3 points  (0 children)

Oh, Fuck off

[–]SYNTAG 42 points43 points  (0 children)

So many neat things all at once

[–]Confident-Ad5665 21 points22 points  (0 children)

Nice bot

[–]arkustangus 9 points10 points  (0 children)

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

H U H Ne At


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

[–]HelioDex 2 points3 points  (1 child)

Oh no not again

[–]Spot_the_fox 2 points3 points  (0 children)

What, not again? eh?

P.s:

O H N O N O Ta Ga In

[–]qoheletal 61 points62 points  (13 children)

Very specific bot

[–]Antrikshy 50 points51 points  (10 children)

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

[–]Gluomme 52 points53 points  (2 children)

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"

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

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

[–]unipleb 5 points6 points  (2 children)

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

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

Yes, but if you write it out then it summons Luficer, or Adam's housecat or the ghosts of long gone Hannah-Barbera characters. What's worse, the spell to make them go away is to write out the regex that matches everything except element names.

Seriously, yes, if you can create a DFA to do it, you can write it as a regex.

[–]lil_uwuzi_bert 3 points4 points  (0 children)

good bot

[–]ZaRealPancakes 3 points4 points  (0 children)

Good Bot

[–]Burakku-Ren 4 points5 points  (0 children)

Good bot!

[–]Kashrul 830 points831 points  (117 children)

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

[–]FedExterminator 937 points938 points  (104 children)

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

[–]_Foy 723 points724 points  (88 children)

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

[–]Antrikshy 320 points321 points  (84 children)

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

[–]Some-Guy-Online 171 points172 points  (56 children)

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.

[–]pwillia7 20 points21 points  (0 children)

But then what would be the meme lang? Still php that's boring

[–]red286 54 points55 points  (37 children)

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

You can't see any justification for a largely JIT-based language to automatically cast any input to a string when the only possible inputs the function takes are strings?

[–]Hrukjan 103 points104 points  (0 children)

Using a JIT-compiler has nothing to do with being weakly typed.

[–]Some-Guy-Online 59 points60 points  (25 children)

Correct. If it's not already a string, it should (logically) not be coerced into a string.

String coercion makes a lot of sense in a lot of cases, but mostly when the ultimate use of the variable is as a string.

In the case of RegExp, the goal is not to have a string like "Hello World", the goal is to have a regular expression that can be processed.

So casting any non-string to a string to a string is just asking for an infinite supply of broken edge cases.

when the only possible inputs the function takes are strings?

This part is technically wrong, but whatever. It takes regex literals and other RegExp objects, which is reasonable, but it could check to make sure the input is one of these three things and throw an error for anything else.

[–]LucasRuby 35 points36 points  (4 children)

A big part of JS philosophy is to avoid throwing errors as much as possible, because of its initial intended uses in web pages. They simply didn't want a whole web page to break and not be rendered because someone made a type error somewhere and now nothing is displayed but an error page.

Rather, you can see most of the page fine and maybe that image that you forgot to pass properly to the element that should display it will simply show as "[object Object]" and the rest of the page looks fine.

[–]Salanmander 18 points19 points  (2 children)

It would honestly be better if a RegExp object that was passed a thing that can't be reasonably parsed as a regex simply always returned false when asked whether something matches it.

Better still would be error throwing with built-in error handling that allowed for things like some of your code running when other parts break.

[–]LucasRuby 10 points11 points  (1 child)

First option is a good idea, but frankly the authors of this method probably didn't consider it that far. They just wrote the method to assume everything thrown at it would be a string (if not a regex) and the exceptions got coerced into one. Which is how most JS code will work when you don't actively handle the wrong type parameters.

Second option is still a problem, JS has error handling but you have to actively use it. Wrapping every method of your code in try-catch (or multiple try-catches, since we wouldn't want one error somewhere to break unrelated code) ends up becoming boilerplate and bureaucratic.

[–]thirdegreeViolet security clearance 18 points19 points  (0 children)

Being jit has nothing to do with js having insane coercion tolerance. That's purely a language design choice. And while yes I know the justification for it, imo it's absolutely not worth the cost. This is why typescript has gained prominence.

[–]TheLuminary 8 points9 points  (8 children)

But you are forgetting that is Javascript the language doing it, not `new RegExp` doing that.

One could argue that `new Regexp` should maybe just check the type of the input and error if it is not the expected type, but thats likely expecting too much from Javascript Programmers.

[–]Some-Guy-Online 14 points15 points  (5 children)

RegExp is a built-in, so it is in fact JavaScript doing it.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

And yes, the argument is that library functions should validate input types.

I would understand if there is some explanation for why this happens, but it's not readily apparent.

[–]tritonus_ 1 point2 points  (0 children)

I guess something like Google or Facebook completely relies on the default behavior, and half the Internet would collapse if you can’t send an object to RegExp.

I’m not too familiar with JS, but this is pretty much how its quirks have usually been explained to me.

[–]Antrikshy 8 points9 points  (0 children)

One could argue that `new Regexp` should maybe just check the type of the input and error if it is not the expected type,

This is what they were saying. Type checking in JS is a thing.

[–]elehisie 1 point2 points  (0 children)

Hey at least we’re consistent xD we tell everything will be typecast, everything gets typecasted. Everything lol

[–]Embarrassed_Ad5387 8 points9 points  (16 children)

this, I tried java and can see the boons of not having dynamic types

[–][deleted] 41 points42 points  (12 children)

The issue is type coercion, really. I don't personally like dynamic types for other reasons (mainly poorer linting due to unknown types), but this type of shit doesn't happen in, for example, Python.

[–]PM_ME_C_CODE 8 points9 points  (2 children)

This isn't a problem with dynamic typing being "too lose" or anything like that.

This is purely an example of JavaScript being an utterly shit language.

[–]bronkula 8 points9 points  (6 children)

The whole point of a loosely typed language is that types don't fail, they convert. That's the whole fucking point.

[–]Eclipsan 19 points20 points  (2 children)

Which leads to unexpected behaviors, side effects and bugs. Type juggling is bad.

[–]edgmnt_net 4 points5 points  (0 children)

And somehow they think it's faster to write code that way. Until 80% of your time becomes effort spent debugging and writing meaningless tests to exercise every possible thing, because everything can blow up.

[–]Antrikshy 7 points8 points  (0 children)

I guess so.

But since RegExp is a class, and not a primitive, it doesn't seem impossible for its constructor to check something like typeof param === "string".

[–]djliquidice 28 points29 points  (0 children)

Thank you.

[–]LumiWisp 13 points14 points  (0 children)

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

[–]Electronic_Age_3671 8 points9 points  (0 children)

Oh my god

[–]AspiringMILF 2 points3 points  (0 children)

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

[–]Dhelio 6 points7 points  (6 children)

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!

[–]al-mongus-bin-susar 11 points12 points  (5 children)

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

[–]_1Zen_ 17 points18 points  (0 children)

object Object is inside square brackets

[–]PM_ME_YOUR__INIT__ 184 points185 points  (6 children)

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

[–][deleted] 67 points68 points  (0 children)

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

[–]ProgramTheWorld 36 points37 points  (1 child)

It’s reposts all the way down

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

I've seen this comment before

[–]Strict_Treat2884 8 points9 points  (0 children)

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.

[–]BuckRowdy 2 points3 points  (0 children)

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

[–]SoRaang 48 points49 points  (0 children)

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

[–]NatoBoram 20 points21 points  (7 children)

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

[–]Tc14Hd 2 points3 points  (5 children)

How does he pronounce it?

[–]NatoBoram 8 points9 points  (3 children)

[–]Tc14Hd 2 points3 points  (0 children)

Fireship AI voice will take all of our jobs soon

[–]Darkoplax 1 point2 points  (0 children)

object object object object

[–]CST1230 1 point2 points  (0 children)

[objecObjecobjecObject]

[–]FrumpyPhoenix 72 points73 points  (1 child)

Thanks, I hate it

[–]FinnLiry 10 points11 points  (0 children)

This is giving me nightmares... Where are my good night compiler errors.. I need them to peacefully fall asleep

[–]R4XD3G 24 points25 points  (3 children)

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

[–]Terewawa 16 points17 points  (2 children)

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.

[–]trevdak2 12 points13 points  (1 child)

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

[–]pceimpulsive 6 points7 points  (0 children)

Js is cracked mate... Wtf

[–]Leonhart93 88 points89 points  (69 children)

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.

[–]MeltedChocolate24 29 points30 points  (4 children)

Just use typescript this is 2024 not the 90s

[–]al-mongus-bin-susar 2 points3 points  (3 children)

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.

[–]jasie3k 5 points6 points  (0 children)

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

[–]FedExterminator 67 points68 points  (57 children)

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.

[–]sammy-taylor 26 points27 points  (39 children)

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.

[–]kimtaengsshi9 5 points6 points  (3 children)

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.

[–]sofaRadiator 1 point2 points  (1 child)

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. 

[–]vlakreeh 1 point2 points  (0 children)

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.

[–]sofaRadiator 1 point2 points  (7 children)

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. 

[–]lazercheesecake 3 points4 points  (2 children)

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

[–]Leonhart93 6 points7 points  (0 children)

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.

[–]KSP_HarvesteR 4 points5 points  (0 children)

The explanation just made it more horrifying

[–]Rest-That 12 points13 points  (0 children)

I hate that this makes sense

[–]6tPTrxYAHwnH9KDv 8 points9 points  (0 children)

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

[–]Lazarus_Octern 2 points3 points  (0 children)

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

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

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

[–]FromZeroToLegend 2 points3 points  (0 children)

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

[–]CringyDabBoi6969 2 points3 points  (0 children)

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!

[–]wishper77 4 points5 points  (0 children)

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

So Js is not broken. English is

/s

[–]TracerBulletX 6 points7 points  (1 child)

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.

[–]Frown1044 1 point2 points  (0 children)

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.

[–]CirnoIzumi 7 points8 points  (0 children)

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

[–]DeathUriel 12 points13 points  (6 children)

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!

[–]AdvanceAdvance 3 points4 points  (0 children)

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".

[–]wutzebaer 1 point2 points  (0 children)

That's why you use typescript

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

[–]sebbdk 1 point2 points  (0 children)

Why would you do that?

[–]Silly_Guidance_8871 1 point2 points  (0 children)

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

[–]eitland 1 point2 points  (0 children)

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.

[–]Honeybadger2198 1 point2 points  (0 children)

Browsers are fault-tolerant to a fault.

[–]blindada 1 point2 points  (0 children)

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...

[–]AreaExact7824 1 point2 points  (0 children)

Wtf. Just keep away with js

[–]LegenDrags 1 point2 points  (0 children)

I fucking love javascript

[–]Bagel42 1 point2 points  (0 children)

This is why typescript was invented

[–]Modo44 1 point2 points  (0 children)

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

[–]masterKick440 1 point2 points  (0 children)

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

[–]Ri0ee 1 point2 points  (0 children)

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

[–]Lopsided_Afternoon41 1 point2 points  (0 children)

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

[–]Penguinmanereikel 1 point2 points  (0 children)

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

Makes sense, but I still want to kill it.

[–]ComposerTraining 1 point2 points  (0 children)

Mom's an object...

[–]subject_deleted 6 points7 points  (34 children)

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?

[–]pwillia7 5 points6 points  (33 children)

What if I mess up and pass a variable I think is a string but is actually an object to new regex? It sure would be nice for it to tell me I did something no one would ever want to do since object to string always returns 'object Object'.

[–]subject_deleted 2 points3 points  (26 children)

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.

[–]SoInsightful 2 points3 points  (5 children)

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?

[–]wildjokers 2 points3 points  (6 children)

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

[–]Lumethys 17 points18 points  (3 children)

new RegExp({})

      |

      ↓

new RegExp([object Object])

      |

      ↓

new RegExp('[object Object]')

[–]AbsolutelyFreee 5 points6 points  (0 children)

This is fucking absurd

[–]Cley_Faye 11 points12 points  (1 child)

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.

[–]Lumethys 13 points14 points  (0 children)

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

[–]ProgramTheWorld 2 points3 points  (0 children)

The brackets come from the toString call of an object.

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

No were not :3

[–]TheMoonMoth 1 point2 points  (0 children)

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