5 Things I Hate About JavaScript

Ғылым және технология

12 Years professional with javascript so here is my list of things I hate about js (this goes for TS too)
Twitch
Everything is built live on twitch
Twitch : bit.ly/3xhFO3E
Discord: discord.gg/ThePrimeagen
Editor
All my videos are edited by Flip. Give him a follow! / flipmediaprod He is also open to do more editing, so slide deeeeeeeeep into his dms.
Links
Linode: linode.com/prime
/ discord
Twitch: / theprimeagen
Insta: / theprimeagen
Twitter: / theprimeagen
VimRC & i3: github.com/ThePrimeagen/.dotf...
Keyboard (15% off, I don't earn commission): bit.ly/primeagen-adv2
#vim #programming #softwareengineering

Пікірлер: 820

  • @ThePrimeagen
    @ThePrimeagen Жыл бұрын

    I didn't include this, bind, type coercion, let dead zones, or any typical "i hate js." I also didn't include Dates because I am convinced that when it was conceived it was considered the best way to handle dates (have you seen other languages in the mid 90s? It was a literal copy of another library at tha time) But the items I included are truly awful items that are not found in other languages (that i know of)

  • @oskrm

    @oskrm

    Жыл бұрын

    This list is a unique one. Not just using the same broken CD.

  • @itspravas

    @itspravas

    Жыл бұрын

    Hello Mr @ThePrimeagent, Big Fan of your twitch stream. What is the green that you're using ? Or it is your wall painted in that color.

  • @DBZM1k3

    @DBZM1k3

    Жыл бұрын

    I think the forEach case is acceptable because sometimes you just want to iterate over the value in some iterable type. So having it value, key allows for key to be ignored entirely giving (val) => {}; Doing it the other way is more complicated to solve for.

  • @beriu3512

    @beriu3512

    Жыл бұрын

    I just read up on `let dead zones` what a peculiar thing, I've never stumbled upon it, and I'm still confused on how someone might reach that edgecase

  • @moodynoob

    @moodynoob

    Жыл бұрын

    Thank you for not using the same lame examples people often use!

  • @alangamer50
    @alangamer50 Жыл бұрын

    as Fireship once said: 'JS is a language used exclusively to build things it's not supposed to'

  • @AEStolfo

    @AEStolfo

    9 ай бұрын

    48 likes and 0 comments? lemme fix it. ...btw fireship rules

  • @dannyarcher6370

    @dannyarcher6370

    2 ай бұрын

    Right from the very beginning.

  • @JuanPablodelaTorre
    @JuanPablodelaTorre Жыл бұрын

    “Any application that can be written in JavaScript will, eventually, be written in JavaScript.” - Jeff Atwood, founder of Stack Overflow, in 2007

  • @j-wenning
    @j-wenning Жыл бұрын

    My "favorite" bit about JS is the fact that you can still manage to create memory leaks in a GCed language, and because of the nature of the language, you're not meant to be actively thinking about that sort of thing, so you don't notice it til your program is whoring an abnormal amount of memory.

  • @j-wenning

    @j-wenning

    Жыл бұрын

    Oh yeah and good luck finding it. Especially if it's an installed dependency and not your own code.

  • @theodorealenas3171

    @theodorealenas3171

    Жыл бұрын

    Ouch. Is that common? I'm not familiar with web dev but it sounds strangely stupid

  • @j-wenning

    @j-wenning

    Жыл бұрын

    For simple applications, no. If you ever start trying to do something clever "just because the compiler/interpreter allows it", that likelihood definitely shoots up, though. Likewise when dealing with lower level data structures and such.

  • @pxh6129

    @pxh6129

    Жыл бұрын

    "whoring an abnormal amount of memory" lmao. I like your phrasing

  • @DFPercush

    @DFPercush

    Жыл бұрын

    I imagine it tends to happen when you have a huge stack of async functions all holding "temporary" named variables full of references to other large structures.

  • @reo101
    @reo101 Жыл бұрын

    Only 5? You must've limited yourself pretty harshly :D

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    have to draw the line somewhere ;)

  • @DMWatchesYoutube

    @DMWatchesYoutube

    Жыл бұрын

    Just spreading the content, don't want people to be overwhelmed

  • @abrahamsimonramirez2933

    @abrahamsimonramirez2933

    4 ай бұрын

    ( ); much better ​@@ThePrimeagen

  • @GeekMasher
    @GeekMasher Жыл бұрын

    "The lords language Rust" made me laugh and started wondering... Are we all created in Rust? Are we all at heart Rustaceans? Are we all... Blazingly fast?

  • @theondono

    @theondono

    Жыл бұрын

    Light is a wave and a particle, Rust doesn’t allow this nonsense. If God had used Rust, quantum physics would make sense

  • @caerphoto

    @caerphoto

    Жыл бұрын

    If we are then I must be running in debug mode or something then :(

  • @tokiomutex4148

    @tokiomutex4148

    Жыл бұрын

    I for sure am

  • @raffimolero64

    @raffimolero64

    Жыл бұрын

    we’re all unsafe code and use garbage collection. somehow at the same time.

  • @tokiomutex4148

    @tokiomutex4148

    Жыл бұрын

    @@raffimolero64 speak for yourself

  • @leetaeryeo5269
    @leetaeryeo5269 Жыл бұрын

    5:36 This leads to one of my hot takes. Javascript is just the BASIC of the 2010-2020s. It's an approachable entry point for new programmers and people want to use it for everything, but that leads to it being used for things it has no business being used for. And everyone and their grandmother has their own library/way of doing things/dialect for any given task, which stretches the language beyond its comfortable limits

  • @hamm8934

    @hamm8934

    Жыл бұрын

    Exactly

  • @aryandeora6631

    @aryandeora6631

    Жыл бұрын

    But isn't that the BEAUTY of it? It can be bent forwards, backwards and upside down and it still works amazingly! Sure there are caveats but which language doesn't?

  • @leetaeryeo5269

    @leetaeryeo5269

    Жыл бұрын

    @@aryandeora6631 I mean, it’s convenient, but I don’t think it’s ideal. Different tools/languages are appropriate for different tasks and trying to fit every task to JavaScript just feels like trying to turn a wrench into a hammer-sure, you can probably get to the same place eventually, but you’d have a way easier and better time if you just stopped and grabbed a hammer. Like, I wouldn’t use JS for systems programming, just as I wouldn’t use C for web ui programming and I wouldn’t develop an operating system APL.

  • @aryandeora6631

    @aryandeora6631

    Жыл бұрын

    @@leetaeryeo5269 fair critique I take your point

  • @leetaeryeo5269

    @leetaeryeo5269

    Жыл бұрын

    @@aryandeora6631 and I 100% see your standpoint as well. I’m a bit of a hypocrite because I work in C# which has libraries and frameworks for pretty much everything under the sun.

  • @peteryates308
    @peteryates308 Жыл бұрын

    I enjoy working in JS from time to time, 0 indexed months get me every time. Every single time.

  • @user-lb1ib8rz4h

    @user-lb1ib8rz4h

    Жыл бұрын

    sure, but that's not js-specific. it seems to have been copied from another language with java in the name...

  • @error.418

    @error.418

    Жыл бұрын

    @@user-lb1ib8rz4h Correct. Also we have a new system coming soon, the TC-39 Temporal proposal which is now in Stage 3.

  • @Yous0147

    @Yous0147

    Жыл бұрын

    @@user-lb1ib8rz4h That's true, but it's been a literal decade since dates have been a problem in Java, if not more. In JS, it's still the same.

  • @RedStone576
    @RedStone576 Жыл бұрын

    this is actually a really great video, talking about stuff that most people will overlook instead of complaining about it's quirks that basically everyone already know

  • @wlockuz4467
    @wlockuz4467 Жыл бұрын

    The regex one has actually screwed me over during my live exams, Luckily I was able to write a shitty function to replace what it was doing, but after the exam when I looked at why it was doing it what it was doing I had the same question, WHY?

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    too clever by half of course

  • @error.418

    @error.418

    Жыл бұрын

    Why were you using a global flag in a test function, though? If you're just doing a boolean test, I can't think of a good example where you actually want the global flag. Without the global flag, this isn't an issue. If you are reaching for the global flag, you're probably intending to use a different regex function, not test.

  • @brunocmesquita
    @brunocmesquita Жыл бұрын

    I knew about your channel a few days ago. What a good content man. Really cool to watch. Contratz!

  • @Kriszzzful
    @Kriszzzful Жыл бұрын

    I was sure when I clicked that this is gonna be just another rant about implicit type conversion. Pleasantly surprised! I wasn’t aware of any of these issues lol

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    Yeah! I tried to be original

  • @BuyMyBeard
    @BuyMyBeard9 ай бұрын

    I remember once making a procedural generation algorithm with a string sequence composed of a combinations of the characters ‘0123’. I wasn’t understanding why it was returning ‘ddeefinnu0123’. Turns out *undefined* was getting cast into a string and then sorted by characters in my algorithm. That had me stumped for a bit.

  • @keatonhatch6213
    @keatonhatch6213 Жыл бұрын

    With css at the stage it’s at and faster backend languages, JavaScript should be limited to web carousels and scroll loading.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    love this idea

  • @Prod-23

    @Prod-23

    Жыл бұрын

    @@ThePrimeagen To be fair, that was the intended use case ... THE ONLY INTENDED USE CASE I might add ... ;)

  • @inakiarias7465

    @inakiarias7465

    Жыл бұрын

    So how would you manage components and application state inside a browser app without JS? Go back to template engines? PHP? Lol

  • @keatonhatch6213

    @keatonhatch6213

    Жыл бұрын

    @@inakiarias7465 you laugh but there’s a reason the largest of web apps still use them.

  • @inakiarias7465

    @inakiarias7465

    11 ай бұрын

    @@keatonhatch6213 Yea, the reason being their code foundation is already built on that...

  • @brianbutton6346
    @brianbutton6346 Жыл бұрын

    Imagine coming to a JavaScript-labeled video and seeing TypeScript.

  • @dannyarcher6370

    @dannyarcher6370

    2 ай бұрын

    I too was thrown.

  • @KnThSelf2ThSelfBTrue
    @KnThSelf2ThSelfBTrue Жыл бұрын

    This isn't a JavaScript but a node issue. If you spawn a child process in node, and that node process logs so much that it crashes due to running out of memory, the callback in the parent process gets passed an exit code of - not a number - but the JS value `null`... which JSers will know is dangerously close to 0. So anyway Jest hurts sometimes.... Don't log a bunch of stuff in your unit tests.

  • @yamogebrewold8620

    @yamogebrewold8620

    10 күн бұрын

    I encountered this problem recently. Jest crashed due to some API call I was making that was spamming warning logs.

  • @nicholaswood3250
    @nicholaswood3250 Жыл бұрын

    I feel like most regex issues are really, “people not admitting that their input is not actually regular” problems. Email addresses are the classic example of something that seems regular but is actually not. The only reliable way to test that an email address is valid is to send an email to it and see if it works.

  • @fearmear
    @fearmear Жыл бұрын

    Here's my suggestion for JavaScript future. Implement TypeScript as a new JavaScript spec and let browsers implement it. I'm tired of having to do "builds" in a scripting language.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    i effing hate the eco system.

  • @theodorealenas3171

    @theodorealenas3171

    Жыл бұрын

    But you also want browsers to pack files for you? And minify? I don't see why or how the browser could build for you.

  • @hacktor_92

    @hacktor_92

    Жыл бұрын

    @@theodorealenas3171 main problem is, doing a simple web ui is waaay more complex nowadays. you don't need angular for a(ny thing) simple blog website. you don't need to build anything complex for a simple task. and nodejs makes you feel like you're in hell.

  • @hacktor_92

    @hacktor_92

    Жыл бұрын

    i'd suggest some sort of apk-like, but for web apps, where you bundle your typescript files, along with assets and whatnot, and the rest is right there, in a single package file.

  • @theodorealenas3171

    @theodorealenas3171

    Жыл бұрын

    @@hacktor_92 sorry I don't have the experience to understand, but APK is a package format apparently. So, you wish to send like a tarball with the dir tree to the browser? You don't like doing the same, but fragmented?

  • @dealloc
    @dealloc Жыл бұрын

    One could argue that forEach taking value first would make other functions easier to reuse for both Map/forEach and Array/forEach. Although, I personally never use forEach for either, since for loops allows for control flow and doesn't make it more unreadable.

  • @ry4nolson

    @ry4nolson

    Жыл бұрын

    it also matches the usage of Array.forEach( (value, index) => { })

  • @weeb3277
    @weeb3277 Жыл бұрын

    Atwood’s Law: “Any application that can be written in JavaScript, will eventually be written in JavaScript.”

  • @blt_r
    @blt_r Жыл бұрын

    callback to Map.prototype.forEach takes (value, key, map) to be in line with Array.prototype.forEach which passes (value, index, array) to its callback. Because indexes for arrays are same thing as keys for maps

  • @claytonmarshall8564

    @claytonmarshall8564

    Жыл бұрын

    Was about to comment the same thing. It would have been much worse had they changed the definition of the forEach callback for a single type.

  • @raffimolero64

    @raffimolero64

    Жыл бұрын

    for consistency the whole thing should just be for v,k if they want to go the route of “you iterate over values but can optionally get the index/key” unless there’s some design philosophy i’m missing, which is likely

  • @falias4

    @falias4

    Жыл бұрын

    thats actually programming 101... In simple for-loops you work with index and in foreach you work with values. (same thing in other languages too) ... and the second parameter is simply optional

  • @arsereg
    @arsereg Жыл бұрын

    Principal Fullstack Lead developer here, 18 years of experience. I found your top things to hate about javascript really interesting and curious! Thanks for sharing! I think, in my personal opinion, that yes, this things can be really cumbersome, and it can lead to really messy situations where you face an additional layer of complexity. And of course, this things can leave you spending hours debugging your code for a piece of code that can be really difficult to find (Like the 'g' operator in the regex). However, the most I hate from Javascript it's a big portion of the community. Don't get me wrong. I've found many many many developers that create a really diverse and collaboratively community that ends up being helpful, thoughtful, and really really good educators about the perks and quirks of Javascript. However, particularly in Javascript and Python, I've also found the most toxic, irreverent and excruciating members I've faced. A few days ago, I found a video in a spanish-speaking channel focused on Javascript developers. The Video title was: "STOP using for cicles". That catched my attention and I went to watch the video. During the video, the presenter mentioned that instead of using "For" to iterate over a cycle, we should do it using a Array.map function, the reason: Legibility. However, during the video, the presenter also mentioned that the use of Array.map function allows you to "execute your code in a immutable way", which seemed kinda odd, because the very fact that you don't modify something during your code execution doesn't make it immutable. In the comments section, I saw one person mentioning how he disagreed with the video, because of multiple things. I added my support to this comment by also mentioning that the video was referring to Immutability when he wasn't actually doing immutability, as well as an improper use of the Array.map function. Not 5 minutes later, I got attacked by one of the people involved on the conversation saying that "Clearly I was just a junior developer that was scared of the Array.map function", and I just mentioned that even that you could achieve the same result using a for or an Array.map function, the Array.map function has much worse performance in terms of memory usage and time complexity. Long story short, I wrote a piece of code to demonstrate how using Array.map performed 28 times slower and could only manage arrays the 1/11 the size in comparison to use a for cicle, not to mention that the Array.map function semantical purpose is to map an object from one type to another, so using a map instead of a for would make the code "harder to read" because the semantics of the code itself. The next day, the youtube channel published a video that was titled: "Do not optimize your code" and pretty much what the video talked about is how nowadays, computers are so powerful that "small" optimizations are unnecessary, using the code I provided in the previous video. To finish up, I just decided to stop wasting my time with someone who's motto is: "Dont optimize your code". The person kept attacking me for around 3 days, trying to pull me into arguments. And although I've found amazing people that makes a great great great community around Javascript, these kinds of interactions are not rare.

  • @talhaakram

    @talhaakram

    Жыл бұрын

    There is this strange culture of putting people on pedestals and treating their opinions as facts or the only right way of doing things. If someone disagrees with it, they are treated as lesser skilled developers who simply 'don't get it'.

  • @arsereg

    @arsereg

    Жыл бұрын

    @@talhaakram Absolutely agree! Also, quite interesting is that as a response for being confronted, he decided to attack me as a person rather than discuss on the technology. This is something we shouldn't do at all when discussing about best methods

  • @upcomingweeb136

    @upcomingweeb136

    Жыл бұрын

    I actually faced similar experience when I tried explaining to some of my colleagues why typescript is better than JavaScript.

  • @arsereg

    @arsereg

    Жыл бұрын

    ​ @Upcoming Weeb! So sorry to hear that. People are afraid of facing new things or not knowing about something. Honestly and personally, I'm glad when I found something I don't know so that I can study it, and I believe that being so aggressive against such scenarios is definitely a lost opportunity to grow. Sometimes, I think that languages get followers that treat said languages with religious fervour. And are willing to negate reality itself just to attach themselves to their point. This person I was talking about before insisted that the use of Map was better, despite the fact that it performed much, much worse, could handle much fewer data and at the cost of code semantics. His words: "This is the javascript way", reveals this religious fervour I'm talking about. For some reason, he thinks that Javascript existed in a separate realm, where code-optimizations, design patterns, algorithms and data structures don't apply to Javascript because "that's just how javascript works". And he's not willing to accept that he's wrong. That also shows a bit of immaturity in the developer as well. In my personal case, I really love and enjoy working with Java/Kotlin. However, I know that Java/Kotlin have their perks and that sometimes it is not the best fit for all. I'm willing to accept that it is "not the best language", but I do not think such a thing exists. Once again, I'm sorry that you had to pass through that trying to educate your colleagues about typescript. However, you are one clear example of how a community around Javascript can also be a really nice place. Let's keep it that way :D

  • @talhaakram

    @talhaakram

    Жыл бұрын

    @@arsereg 💯 agreed.

  • @AnalyticMinded
    @AnalyticMinded Жыл бұрын

    I just started learning a bit of JavaScript a couple of days ago, so most of this video just flew over my head. But the important thing is that I watched it. :P

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    agreed. its like a boomerang, it flew over, but its coming back.

  • @eventslooped7376

    @eventslooped7376

    Жыл бұрын

    @@ThePrimeagen Deep. And when it comes back it hits you in the back of the head

  • @__idan__
    @__idan__ Жыл бұрын

    Modern life as we know it is standing on the thin legs of JS, I'm scared.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    hahaha

  • @konga8165
    @konga8165 Жыл бұрын

    Love you man! Keep it up!

  • @KoltPenny
    @KoltPenny Жыл бұрын

    6. Starts with JAVA

  • @altairbueno5637

    @altairbueno5637

    Жыл бұрын

    Even java knows about OR numbers

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    proof its bad

  • @quentincaldway
    @quentincaldway Жыл бұрын

    The"Bruh" gets me every time! 🤣. Now I need a video on 10 things you Love about rust....Yes....I'm asking for 10 lol. You're hilarious....Your brain oozes with knowledge! Appreciate the value you always give brother! Hope you catch a break with that project you're working on with Netflix lol can't imagine. ~Blessings!

  • @EvanBurnetteMusic
    @EvanBurnetteMusic Жыл бұрын

    Having the user name multiple implicit return variables is the root of the k v mixup. I'm surprised more people don't talk about this! Fundamentally, if programmers cannot easily see how data is being transformed, they will not be able to find and fix problems.

  • @error.418

    @error.418

    Жыл бұрын

    It's not even really a mixup. Array functions like forEach, map, and filter all have consistent parameter order and in a sensible order since often for those functions the user just wants to use the value and not the index. That you can destructure the array returned by an Object.entries into [key,value] is a language feature that came much later and has a very different context. I didn't see this one as an issue at all.

  • @Yous0147

    @Yous0147

    Жыл бұрын

    @@error.418 The implementation detail of it is logical enough, the problem comes when you use it. Logically you'd always expect key, then value, as in key-value pair. Suddenly having to deal with turning that idea around because of an implementation detail is not only problematic, it's incredibly limiting. It's not the worst here , but this aspect has bitten me numerous times when using JS libraries.

  • @sct848
    @sct848 Жыл бұрын

    Man your videos are very entertaining

  • @earthling_parth
    @earthling_parth Жыл бұрын

    Yayy! We will finally get to learn the history behind the name - Primeagen when this channel hits 100K subs. My theory is that it's something related to the 'next-gen(eration)' of the Optimus prime and/or maybe gaming.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    not even close

  • @wilfridtaylor
    @wilfridtaylor Жыл бұрын

    Yeah my rule for javascript is contain it on the front end. Don't let it get into cicd to much or you end up with a really flaky build system.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    yep

  • @floppa9415
    @floppa941511 ай бұрын

    One that also got me good a few times are the standard lib's array functions. Some of them like filter or map return you a shallow copy but some like splice, sort, reverse don't.

  • @studiousllama4776

    @studiousllama4776

    9 ай бұрын

    omg seriously. Thankfully all the major browsers now support toSorted, toReversed, etc., so hopefully soon we'll be able to start using those instead

  • @niles_5003
    @niles_5003 Жыл бұрын

    One time I used an object as a lookup table rather than using a Map. Turns out you can index it with the names of the members of the built-in `Object` and TypeScript won't save you. It was kind of a funny bug because it's one of those things where you can know the codebase inside and out and then you see the output being a stringified method of `Object` and if you never realized this fact before you'll think to yourself, "Where on earth could we possibly have any code that could produce such a result?" Luckily I realized pretty quickly what was going on, but I could imagine that someone could have taken many hours to figure that one out.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    yikes

  • @error.418

    @error.418

    Жыл бұрын

    For example you used "entries" as a key?

  • @niles_5003

    @niles_5003

    Жыл бұрын

    ​@@error.418 The issue was not the data that was stored inside the object. The issue was doing a lookup in the object with an arbitrary string, and expecting it to return one of the values in the object or undefined.

  • @error.418

    @error.418

    Жыл бұрын

    @@niles_5003 Yeah, unless you set the object `as const` or use the `` prefix then it doesn't try to protect you, gotcha.

  • @aymenmt1
    @aymenmt1 Жыл бұрын

    Math.max(); // -Infinity Math.min(); // Infinity

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    ... that cannot be real

  • @hamzazouari999

    @hamzazouari999

    Жыл бұрын

    @@ThePrimeagen i actually had to test it, he is right, oh hell nauugh

  • @basudevadhikari22

    @basudevadhikari22

    Жыл бұрын

    My goodness!

  • @pryflack3646

    @pryflack3646

    Жыл бұрын

    OMG it’s true! 🤣

  • @astroid-ws4py

    @astroid-ws4py

    Жыл бұрын

    Holy Fk, It is true, Thanks god I am not working with JavaScript.

  • @scottiedoesno
    @scottiedoesno Жыл бұрын

    Silly footgun (and one that does somewhat fall into your type coercion moratorium), but checking whether a variable is undefined vs truthy or falsy as a practice (e.g. foo && ... ) has just caused no end of headaches for my applications in the past. Probably more of a best practices thing and goes back to the community being the problem, but it's still unbelievably aggravating.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    yeah, i really hate that one.

  • @bigmistqke

    @bigmistqke

    Жыл бұрын

    I ve written a lil package for it. Rn it's pretty dumb, it just checks if the falsey is not 0 or "", cause those are the situations that i came across that really tripped me up.

  • @kevinbatdorf

    @kevinbatdorf

    Жыл бұрын

    This is a React concern. As a policy, always check item?.length > 0 and use a ternary

  • @hakooplayplay3212

    @hakooplayplay3212

    Жыл бұрын

    @@kevinbatdorf yea, ?. I a nice one, but im workin on aws lambda and we have node12 here ... So damn tired of this && checks

  • @niles_5003

    @niles_5003

    Жыл бұрын

    Could you give an example of a situation that trips people up? And were you using TypeScript at all?

  • @travispulley5288
    @travispulley5288 Жыл бұрын

    to answer "why?" @3:43 - because the key value isn't used sometimes in forEach blocks and it makes the code tidier to ignore a var/arg in this way, but also it's available when/if you need it. Madness? Perhaps, but there is a method to it

  • @GiveMeSomeMeshuggah

    @GiveMeSomeMeshuggah

    Жыл бұрын

    That’s what we get for not enforcing function arity

  • @mister-zen8491

    @mister-zen8491

    3 ай бұрын

    So, we are all trusting the JavaScript based on 'Maybe we need it, but maybe we don't'?

  • @gpcureton
    @gpcureton Жыл бұрын

    I've watched the Twitch stream you made a few days ago where you wrote a plugin. I bounced around the VOD looking, but I couldn't figure out what the hell it was for. Was it so you could do the "unfolding code" animation starting at 2:56?

  • @oskrm
    @oskrm Жыл бұрын

    Clearly, [] is the same as 0. IDK how you'ren't seeing it.

  • @user-he4ef9br7z

    @user-he4ef9br7z

    Жыл бұрын

    If you're drunk they even look the same.

  • @kristun216

    @kristun216

    Жыл бұрын

    Loose comparison do be like that in dynamic languages

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    you are perfectly correct, drunkeness is the real reason [] = 0

  • @amirosman8797
    @amirosman8797 Жыл бұрын

    Totally agree with everything you say, but enough with JavaScript we are waiting for the Elixir video, we need to know your thoughts on Elixir against Go, Rust and JavaScript.

  • @t3dotgg
    @t3dotgg Жыл бұрын

    Banger video tbh

  • @codemastercpp
    @codemastercpp Жыл бұрын

    Heyyyy, that javascript tea pouring meme was provided by me :D

  • @justafreak15able
    @justafreak15able Жыл бұрын

    @ThePrimeagen Can you make a video on how to replace Regex with a better solution for field validations and all.

  • @alexIVMKD
    @alexIVMKD Жыл бұрын

    Reminded me of a clip from Fridman's podcast about how "less than ideal" languages are so widely used, quite the mystery honestly... It was my first language but I am seeking to accept the lord in my heart by learning some rust-lang, hopefully

  • @craigasketch
    @craigasketch Жыл бұрын

    toFixed(2) returns a string got me today. Basically the entirety of Js's number system.

  • @Rodriyabala
    @Rodriyabala Жыл бұрын

    Prime you've uploaded a video working with the rust framework for web dev "Yew", with assembly around is there something like that but for go?

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    that i don't know

  • @SchneiderRob
    @SchneiderRob Жыл бұрын

    I wasn't subscribed. I thought I was a subscriber. But I was not. Now I am. I hope you hit 100k soon dude. Love the videos. Awesome show! Great Job!

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    thanks man! i am so so so close!

  • @Chris-ln3xe
    @Chris-ln3xe Жыл бұрын

    1:34 What is the alternative to regex? how do you validate input to an API?

  • @effoffutube
    @effoffutube Жыл бұрын

    I like how you've twisted your rage into joviality.

  • @Rudxain
    @Rudxain Жыл бұрын

    2:55 actually, any kind of array of primitives will be shallow-copied, it's just that doing a deep-copy behaves exactly the same, because primitives aren't objects. Buffers are part of NodeJS. It seems the slice method does a pointer-copy (pass by reference) on Buffers. You should blame NodeJS, not ECMAScript

  • @DragonRaider5
    @DragonRaider5 Жыл бұрын

    From my perspective the forEach is reasonable, because for arrays etc. it also gives you value first, key second. Mabye the issue was introducing these functions in the first place, no idea why for shouldn't cut it.

  • @darkosimonovski3653

    @darkosimonovski3653

    8 ай бұрын

    thank you

  • @davidattlee2734
    @davidattlee2734 Жыл бұрын

    I want that backstory to the Primeagen. 100k special plz.

  • @kelvindecosta5350
    @kelvindecosta5350 Жыл бұрын

    I don't necessarily hate this about JS / Web ecosystem, but I don't like it either; there are so many different tools that can combine to do the same / almost the same task. When I started, I was introduced to tools like ES Lint, TypeScript, Webpack, etc. A while back I had to deploy a no longer maintained project ("fbctf" for those that are curious) and I was introduced to a relic called Grunt. Now everyone is hyped about Deno, Bun, Vite, Snowpack. It's nice that the community is building on each other's work but I can't help but feel like everyone is reinventing the wheel. I can't imagine how new developers feel about this. The same can be said for Python's dependency management solution. I don't remember the XKCD strip that discusses this obsession with creating new tools that do pretty much the same thing.

  • @charlesselrachski34

    @charlesselrachski34

    Жыл бұрын

    nim/go/zig/phix-lang/vlang bro , problems solved... use the better languages

  • @FADHsquared

    @FADHsquared

    Жыл бұрын

    The xkcd is something like this: There are 14 competing solutions, ha, we have to make a solution that works for everyone! Now there are 15 competing solutions.

  • @dealloc

    @dealloc

    Жыл бұрын

    Not unique to JS. C/C++ has how many compilers and tools for building C/C++ source code? The thing is that as languages evolved, so does the tools; As things become more standardized, tools tend to follow the good standards that makes it easier for developers to provide good UX. First DX was at the front, now it's the UX and the tools we have allows for better UX while also providing good DX (in terms of not having to configure everything from bottom up to provide good UX) by being more opinionated.

  • @SimonBuchanNz

    @SimonBuchanNz

    Жыл бұрын

    As someone who is currently sitting on an internal custom task runner script that's grown into an entire library with a plugin system, variable expansion, config file validation, dry run, caching, etc....? It's because it's so easy to get the 80% you care about done when you hit some case that doesn't work well with the existing tools, and it's so easy to add features after that. Bundling is a great example of this, where your internal crappy tool can get thrown together in an afternoon and be useful, and the existing tools are good at one thing but bad at others. Even then, there are only really two "real" bundlers out there right now: webpack and rollup, and the rest are all written on top of that (though the awesome swc project is working on one too, which should be amazing for my build times!)

  • @jandresfg
    @jandresfg Жыл бұрын

    Storing functions as consts will always rub me the wrong way, but I've become used to it. Also, the fact that a function may or may not receive an argument is just weird -it always frustrates me when I realize something I needed in my code was given to me all along via an angument I neglected until now 😑

  • @SimonBuchanNz

    @SimonBuchanNz

    Жыл бұрын

    As in, when you're implementing a callback? That's one of the less talked about benefits of Typescript, the editor will tell you what arguments you can add. This one doesn't even need you to be writing Typescript, just have typings installed!

  • @xdman2956

    @xdman2956

    Жыл бұрын

    all the key, value vs value,key vs wtf are the arguments make js hard to write without help of an ide, however ide suggestions mitigate this this is a bit worse emotioinally, cuz you realize you wasted time for worse reinvention of a wheel, tedious and rather dumb

  • @katjapotensky4054
    @katjapotensky4054 Жыл бұрын

    Just wondering, how would typescript catch the uint8array problem? Buffer probably extends uint8array which makes this correct behaviour as far as typescript is concerned? Special treatment for OO hierarchies just for buffers?

  • @xBZZZZyt
    @xBZZZZyt Жыл бұрын

    02:58 you can use Uint8Array.prototype.slice.call(buffer,start,end) to always deep copy

  • @nwachukwuujubuonu6345
    @nwachukwuujubuonu6345 Жыл бұрын

    What alternative to regex would you recommend?

  • @Hunsenbargen
    @Hunsenbargen Жыл бұрын

    I don't know why, but I just laugh at the Map/forEach thing. It's so dumb hahahaha. Btw, what do you think about .NET? is there any chance for a video about .NET vs Rust vs Go?

  • @stephenJpollei
    @stephenJpollei Жыл бұрын

    I actually really like regexps, but never use the g flag. I also tend to write regexps that are anchored and don't have multiple ways that they can match. I kind of wish that raku style regexps and friends were available in more languages. The using signed 32bit for bit-ops is super gross.

  • @taragnor
    @taragnor Жыл бұрын

    My personal favorite is that NaN (not a number) has the type "number."

  • @mjrduff-gaming2365
    @mjrduff-gaming2365 Жыл бұрын

    Last time in typescript, I figured out that, any regexp for an HTML file does not show you all groups that match you regexp. If you write it like that /href="(\/[\w]+)"/g or as new RegExp(/href="(\/[\w]+)"/, "g") It matches only the first match while using exec, but string.match shows you all matches. But no groups, only full matches

  • @dealloc

    @dealloc

    Жыл бұрын

    Don’t use regex to parse HTML. Ever.

  • @matiasbpg
    @matiasbpg Жыл бұрын

    First, love your videos as always. Didn't you leave Netflix? I remember a vlog you weren't happy at how that went. Now I'm not sure lol, but if you returned to Netflix I just wanna say I'm happy you.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    if you watched the full vid i explain at the end someone brought me back in :)

  • @matiasbpg

    @matiasbpg

    Жыл бұрын

    @@ThePrimeagen I missed that completely hahaha. Anyways happy for you it worked out!

  • @muhamadluthfia2580
    @muhamadluthfia2580 Жыл бұрын

    Nice video, it works!

  • @maxwellhunt3732
    @maxwellhunt373211 ай бұрын

    The fact that the condition undefined > 0 simply evaluates to false and doesn't cause any sort of error has caused me endless pain debugging at work. When there's a function which isn't working probably, returning undefined instead of a number, which then gets compared to 0 and there's no way of knowing.

  • @jepemz873
    @jepemz873 Жыл бұрын

    An object will keep the keys in order of insertion... except for numbers. I know I should have used a map but objects serialize easily.

  • @jsonkody
    @jsonkody Жыл бұрын

    Hmm .. if you show that FOR and FOR_EACH next each other it looks strange but it's kinda consistent from other standpoint -> FOR just iterate on key:value pairs while those functional methods like .map .filter .forEach .. they use index just as optional second argument(or key in this case) but they always use value as first 'thing'/argument/whatever -> and they work somewhat like this in many languages I think .. so it does make sense :D Thx for the video

  • @Zooiest
    @Zooiest Жыл бұрын

    More on reference types and shallow copying, if you `.fill()` a (regular) array with one, all indices point to the same object const arr = new Array(5).fill({}); arr[0].a = "Hi Primeagen"; console.log(arr[2].a);

  • @Nellak2011
    @Nellak20118 ай бұрын

    One thing that JS does that messes with me when I try to do FP in JS is that JS passes the variables by reference, and I can accidentally mutate state, even when I am trying my best not to. This leads to unexpected behavior and confusion because my "pure" function is making side effects.

  • @noahsark9398
    @noahsark9398 Жыл бұрын

    Can someone explain the third reason to me? Is it because when you do a forEach on a Map the second argument becomes key instead of index?

  • @owlsmath
    @owlsmath Жыл бұрын

    What do you use instead of regex? I understand you try not to use it if you don’t have to but what’s the better method?

  • @dealloc

    @dealloc

    Жыл бұрын

    Either minimum effort (i.e. for email only check if @ is present, send an email to the user to confirm that the email is valid), or if you must parse things like HTML or other markup, use a proper parser that can tokenize and correctly follow a spec and will likely be faster than Regex, and can sanitize user input (i.e. for HTML parsing). Another issue that Regex has is that it can be very slow for large inputs, which means that passing user input directly into regex validators can result in denial of service attacks (ReDoS) and halt your program indefinitely until timeout or restart.

  • @owlsmath

    @owlsmath

    Жыл бұрын

    @@dealloc Thanks

  • @owlsmath

    @owlsmath

    Жыл бұрын

    @Maksim Verkhoturov Yes makes sense. Thanks

  • @lpanebr
    @lpanebr Жыл бұрын

    In love regular expressions!

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    DONT DO IT

  • @SirusStarTV
    @SirusStarTV Жыл бұрын

    Array.prototype methods use (value, index, array) order of arguments (reverse of array[index] -> value), you don't always need index of value when iterating over arrays. Objects aren't iterable so "for of" doesn't work for them, only "for in" for iterating over keys only, Object.entries() does give them iterable functionality and neat syntax of destructuring like [key, value].

  • @adrianburgoscolas520
    @adrianburgoscolas520 Жыл бұрын

    i've just been bitten by the bitwise operation thing 🤣

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    its so frustrating

  • @EvanBoldt
    @EvanBoldt Жыл бұрын

    The worst one to me is the behavior of "this" on UI callbacks like click.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    Shockingly that's never bothered me. The rule is stupid, but I get it

  • @ivoevansstorrie3916
    @ivoevansstorrie3916 Жыл бұрын

    This got me once: function average(averages: number[]) { return averages.reduce((sum, n) => sum + n) / average.length } we divide by average.length, not averages.length, and average.length is for some reason the number of arguments the function takes.

  • @leilafarahmoussa

    @leilafarahmoussa

    Жыл бұрын

    This is cursed

  • @javascripttalks
    @javascripttalks Жыл бұрын

    I completely agree that JavaScript was designed for web UI dev and It should be used that way. Most UI developers don't need bit manipulations anyway. Just because you can develop low level networking stuffs with js, doesn't mean you should do. I think developers nowadays are too lazy to learn another language and keep pushing javascript everywhere. Some people think C/C++ is for old people and JS is cool :D

  • @error.418

    @error.418

    Жыл бұрын

    I really hope you're not writing backend with C/C++ when we have much better languages for that domain...

  • @artemeelemann317
    @artemeelemann317 Жыл бұрын

    The forEach for map works like just for regular array when you use forEach you get (value, index) not (index, value)

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    yes and its really dumb for a map i have several questions for those forEach'ing over map, especially value first. its a terrible api design.

  • @anisoseryx
    @anisoseryx Жыл бұрын

    Lemme add number 6, this keyword with functions When I started to learn I used a normal anonymous function instead of arrow function within a class, i never suffered like that hour all I needed was the arrow function Number 7 threading: the reason why I switched to another lang whenever I needed threading it's pain =(

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    hah. I didn't want to talk about this. everyone knows about this being a bit confusing. And threading! Its the reason why people _like_ javascript unironically.

  • @sagarrajak6996

    @sagarrajak6996

    Жыл бұрын

    Use promise brooo

  • @anisoseryx

    @anisoseryx

    Жыл бұрын

    @@ThePrimeagen I liked at first too I was like woaaa it's cool but it's absolutely painful xd

  • @parlor3115

    @parlor3115

    Жыл бұрын

    @@anisoseryx No it's not. Promises is a really great API and I see a lot of languages having a similar approach to async programming.

  • @anisoseryx

    @anisoseryx

    Жыл бұрын

    @@parlor3115 the prove isn't with promises I use them all the time dw, it's for certain cases where threading becomes painful like when I made a discord api wrapper I needed some variables to be shared and it was a real pain to get it done since my variables were constantly changing and needed to be updated across all threads, you can see how complex this problem can be by checking djs code they do that too. Long story short threads are nice but Javascript isn't made for this and I prefer to use another language like csharp to tackle it

  • @srirajnair2594
    @srirajnair2594 Жыл бұрын

    You said not to use regex , but what is the other alternative to that?

  • @GiveMeSomeMeshuggah

    @GiveMeSomeMeshuggah

    Жыл бұрын

    For HTML, use a dedicated parsing library, since HTML is not a regular language. If you’re trying to parse a regular language, there are libraries that allow you to write out a grammar and visit each node of the parse tree. This is a lot less brittle than trying to debug a manual regex parser when the spec changes. And then if you have a use case that’s not a regular grammar and/or you can’t use a library for, (I’m so sorry) reading char-by-char and parsing that way will often be faster and less error prone than a regex.

  • @arsnakehert
    @arsnakehert Жыл бұрын

    The (value, key) in forEach actually makes sense and is kind of expected, typically optional arguments in programming languages come in a “most optional comes last” kind of fashion, and typically with forEach you only want to iterate over values, with the index or key being the optional argument in the lambda, so it makes sense that it comes after the “less optional” argument

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    This is only an argument in js that makes sense. Go, rust, cpp, lua, who knows else don't do this

  • @theodorealenas3171

    @theodorealenas3171

    Жыл бұрын

    It clicked instantly to me, when I first used it a few months ago. And that's the reason it clicked too. But yes Python doesn't do that. Also I thought I'm the only one who comes back to this video periodically

  • @arsnakehert

    @arsnakehert

    Жыл бұрын

    @@ThePrimeagen Sorry, when I said "typically in forEach" I meant typically in forEach as used in JS specifically

  • @CheefCoach

    @CheefCoach

    Жыл бұрын

    @@ThePrimeagen Lucee does. I am pretty sure that php is doing that as well.

  • @GreyDeathVaccine

    @GreyDeathVaccine

    Жыл бұрын

    @@CheefCoach It's wierd in PHP. We have optional indexing but it is in correct order. With index foreach($array as $key => $value) Without index foreach($array as $value) So it is obvious. Just look for => 🙂

  • @just_ppe
    @just_ppe Жыл бұрын

    The thing with regexp really made me rethinking my life choices back then...

  • @TheStruders
    @TheStruders Жыл бұрын

    TypeScript is ok when deploying to AWS Lambda or another serverless cloud function. We can get features/services out so fast, and when our company needs money, it's keeps us going

  • @BlitzkriegHD
    @BlitzkriegHD Жыл бұрын

    Gotta say, right off the bat you mentioned the global regex flag and I audibly YELLED after realizing THAT was the reason of some annoying bug in a project I have been working on. Strong start hahaha

  • @Inconito___
    @Inconito___ Жыл бұрын

    Personally the thing I hate the most in JS are callback function, why people don't just use async await , that would make my life far better (beside that I hate undefined , this should output an error and force you to handle it like any other programming languages)

  • @RobertoMaurizzi

    @RobertoMaurizzi

    Жыл бұрын

    ... and it does the same if you divide by zero... -____-

  • @Kaiju3301
    @Kaiju3301 Жыл бұрын

    JavaScript isn’t my favorite but I keep a toaster in my bathroom with a php sticker on it just in case.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    this seems to be the most reasonable

  • @sadikkadom9566
    @sadikkadom9566 Жыл бұрын

    Is it possible to create the C language from Javascript to make Javascript faster?

  • @Manana7016
    @Manana70169 ай бұрын

    You covered a lot of stuff that I don’t think is covered in Bootcamp and tutorials. Seems you tell things like they are. I’d be really interested on your take on self-taught developers. Not just no CS degree. Self taught with no degree period. How well do they do?

  • @Khusyasy
    @Khusyasy Жыл бұрын

    yeah i really hate the regex thing, once i tried to use it to parse data from a string, and it didn't work because i need to use matchAll instead of just match with the g flag

  • @dreamsavior1317
    @dreamsavior131711 ай бұрын

    I liked it when JS' forEach used value, key. Because in most cases we needed the value instead the key. It would be silly to write .foreach((undefined, value) => ...)when we just needed the value.

  • @oussamabouchebak6877
    @oussamabouchebak6877 Жыл бұрын

    So you suggested we avoid using regex, so what's an alternative to testing a pattern on a string?

  • @fearmear

    @fearmear

    Жыл бұрын

    Use String.prototype.match instead

  • @LeagueJeffreyG
    @LeagueJeffreyG5 ай бұрын

    If you add a number to a set and check if that number exists. It returns false because set converts all numbers into a string

  • @hsrkfzycfod8
    @hsrkfzycfod8 Жыл бұрын

    ThePrimeagen's gonna carry us to the top, bruh. 2023 is gonna be the year of Rust and NeoVim.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    agreed

  • @harleyspeedthrust4013
    @harleyspeedthrust4013 Жыл бұрын

    I built the account creation page for our site, and I used a regex to validate emails. To be fair it's very loose validation to make sure you have some stuff, followed by an @, with some more stuff containing a dot at the end. And I know there's a bunch of bullshit RFC edge cases and I'm sure it doesn't work on at least a few of them but I don't give a shit because nobody uses email addresses like that anyway, and if they do then they should know they aren't welcome.

  • @briansalkas349
    @briansalkas349 Жыл бұрын

    No custom equality for maps. If your key is an object you can't use a field to check if its already there. This has caused me to either avoid maps or use maps in very weird ways.

  • @rhemtro
    @rhemtro Жыл бұрын

    the null and 0 stuff always gets me confused...also after discovering golang javascript looks confusing too

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    yeah, yavacript is a bit interesting

  • @u9vata
    @u9vata Жыл бұрын

    When interfacing JS or TS people from my C++ code what I hate most is that they silently send you json with all kinds of shit in it - that is invisible to them because of JS-sloppyness... Like when they randomly send "empty string" instaed of null, undefined as string and such horrible pieces of shit. My code is having tens of special cases for parsing their fucked up shit :D

  • @tiberius9283
    @tiberius9283 Жыл бұрын

    How do you not use regex? Many times it's the best option, can someone elaborate a bit? thanks EDIT: Found the answer in the comment :)

  • @romanext921
    @romanext921 Жыл бұрын

    Javascript Dates are amazing! I think the day of the month starts at 1?

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    everything is 1 based unless its not

  • @camiloromero7633
    @camiloromero7633 Жыл бұрын

    Nice plugin to auto write. Did you get it working at first time? *Nice stream BTW*. Keep up with that awesome content 💪🏽

  • @b1chler
    @b1chler Жыл бұрын

    The single most annoying part imho is the lack of standards. There r 100x different ways of doing things one more ugly then the other. Crap gets added with every JS version but nothing gets deleted. It’s just like a teenagers room. Dirty, stinky and full of smartasses.

  • @michalatlas2865
    @michalatlas2865 Жыл бұрын

    Alright, awesome, I agree that regexes are kinda hard to verify and I'll use them only for quick shell scripts and for find and replace........ What now tho? You can't just say avoid something that's used so widely (ofc, I understand this is just a short video), should I write a grammar and a parser for it instead? Tbh, now I think about it that would be kinda cool. But tell me, what's your idea of a replacement?

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    honestly, plenty of easy things. take this for example. you want to validate its a vim cmd. well.. you probably reach for a regex. Hold on devil. let index = cmd.chars().position(|c| !c.is_ascii_digit()).unwrap(); let (num, cmd) = cmd.split_at(index); let num_res = str::parse::(num); Rust code. Its easy, its easier to understand than a regex, and its performance is well understood.

  • @tiberius9283

    @tiberius9283

    Жыл бұрын

    @@ThePrimeagen What about stuff like email or particular codes like IBAN? can you do without regex?

Келесі