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)
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.
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
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?
@@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 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.
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?
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.
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.
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'.
@@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
@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
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
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
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
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.
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.
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.
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
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.
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.
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 =(
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.
@@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
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
@@ThePrimeagen which type? Although parsers require more code and are slower for short convoluted patterns. Don't you think? On the other hand, parsers are more easily read by humans. Wouldn't regex be "blazingly fast" compared to parsers ? Don't get me wrong, I love me some PEGs
The best place to use regex is for things that you know for a fact that has a very rigid and predictable pattern. Like repetitive codes and languages. Or just a quick tool for extracting data from large amount of text that you need very often. What regex is really not good at is filtering things that are potentially bad for your purposes.
As a library maintainer... my least favorite part of JS is the lack of ECMAScript feature support among the various bundlers and frameworks. The number of issues where "it doesn't work in my React Native app bundled with this new bundling framework that doesn't even say it guarantees support for RN... but for some reason I thought it was your fault so fix it now, slave!" is literally the body of the issue are too damn high... I swear, I tried moving from ES5 to ES6, and people complain about everything. BigInt has been stable and in every browser and NodeJS install under the sun for almost a decade and literally people freaked when I tried to use it and it broke their shit. WHY ARE WE ETERNALLY STUCK AS LIBRARY DEVS ONLY USING ES5!?!?!?!? *pulls out hair* I need a coffee, but it reminds me of JavaScript so I've sworn off the stuff.
Not sure this is bundler issue more than it is configuration/user issue. Most bundlers supports downlevelling ES (i.e. with Babel). Although not unique to JS world, I agree that tools can make end-user think OSS library maintainers are at fault for their broken software is a problem.
This is actually a case where JS is ahead of other languages, if not perfect: Rust literally just updated their minimum Linux kernel version from 2.6.32 to 3.2 - which came out nearly a decade ago. At least with JavaScript's bundling and polyfilling environment you have a fighting chance of taking a library published using all the latest and greatest features and running it in IE5.5 for Mac. I mean it sucks to do so, but you can...
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!
The forEach callback receiving the value first allows the programmer to save a few keystrokes in the common case of using only the value and not the key... So, yay! for a little longer keyboard lifespan and one fewer unused argument...
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].
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
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.
I’m surprised that Netflix isn’t using erlang or elixir given how good they are for multi connection services. Imagine having to rewrite the whole backend with rust…but I guess you can use wasm so it could all be rust.
@@oskrm not as tried and teated as other languages, harder to find devs for, has a reputation for being associated with blockchain hopefully time will fix these issues
I'm working with an API that uses 64bit integers as IDs, I couldn't figure out why all of them were getting rounded for the longest time haha. Gotta love that lost precision.
doesn't that just hurt? You have to do the WORST thing in javascript. You either a use big int conversion (then you have to make sure your endians are good) or you keep 2 part keys. just the worst.
immutability wasn’t really a trend until about 5 years ago, so JS still has a bunch of clunky mutable stuff going on. Another classic one is .sort which mutates the source AND returns it.
yeah, the returning it really is a bad api. I am happy that its in place sort (the performance would just be so annoying if it wasn't) but returning it gives such a different impression
@@bigmistqke Lots of people think that. JS should have added a separate method like sortReturn or something to let people choose. You can spread it though like [...items].sort()
@@bigmistqke yeah it does, which like prime said, is good, but also bad because the return gives another impression. If you aren’t doing anything too crazy you can spread the array before calling sort for an immutable sort
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.
1. why is REGEX bad ? i was recently working with MQTT a lot and was using it most of the time 2. i never really used Buffer or UintArray API's at all directly. In which cases are these actually needed? Im just doing TS for 2yrs so eli5 please
1. you overmatch regex's all the time. they are also performance nightmares. they also are known for the Regex DOS 2. when you need to work with contiguous memory
Prototypes! When you go around Stackoverflow, tutorials, videos. You see it a lot. Just modify the Prototype of the object you are working with. So just change the __proto__ of the array and make it work for you... Not knowing that when you change the prototype of a common type/object, you change it EVERYWHERE not only in your func or lines of code. Maybe not a JS language problem, but more a trap for beginning developers, espcially when not being though wel what the prototype actually is and what it does.
It is not just one or two senior devs that I have had to explain how to remove an event listener in vanilla JS. For some reason, people fail it invariably even after reading the spec. Twice. Or thrice. And people also seem to lack understanding of this. I have been told more than once that webcomponents are nice but it cannot see my context x or assign a listener to button y to use itself because no visibility. Well, just bind. It looks ugly but it is what it is. And I am not even a dev but a consultant who does not do any coding. But still I run a ross devs who know less JS than I do… having to explain a use case for a function closure, or the difference between DOM node types 1 and 3, or why you cannot set :focus state on a non-interactive DOM element without tabindexing it with -1 first, etc. One need not explain pointers to C developers, but JS people are often lacking even the basics.
the riddles on getting nested variables to be validated before nulish coalesing was inveted is something that triggers me a lot... if(a && a.b && a.b.c && a.b.c.d) { // do that }... Other thing my experience with javascript catches me is when you are dealing comparisons that may return 0, because 0 is evaluated to false, how about that: if(a===b) { // do that } where b is 0, // will evaluate to false, and will not proceed. lol
Here is another one, you would expect somearray.every(condition) to return true if the condition is true, which works fine untill the array is empty, then it return false, which is very misleading, Same for somearray,some
3:42 bruh, I hate JS as much as anyone here, but you're ignoring something obvious. forEach is usually used for iterating over values, indices are (almost alaways) useless. Image having to write `arr.forEach((_, v) => v)` everytime you want to ignore the index. This is why `for x of array` iterates only over values. You can do: ``` [...Object.entries(arr)] .forEach(([i, v]) => {}) ``` To get the order you expect. Of course, that code has too much boilerplate, so we'll have to wait for the iterator-helpers proposal to reach Stage 4
JavaScript has so many edge cases with weird explanations why something happens that you just literally have to keep track of all of these strange behaviors instead of doing your job. I can't stand it sometimes. You just can't learn JavaScript. It brings the new surprise to me every day. And I have been a frontend developer for 7 years...
Email regex validation is very easy when you learn that the TLD isn't required for emails and symbols like +, - are valid. Knowing the spec halves the regex expression :^)
I really wonder what people are even checking for when they are doing email validation. If it's just whether someone didn't understand that it was an email field, just check if it contains an @. Otherwise you're not going to be able to check if it actually exists or whatever!
what makes me confused is why does JS have bitwise operators and systems level stuff when it was meant for adding function to websites and not system level stuff like OS's. 💀 also bit wise or takes the or value of each bit like in an integer like this 10 can be represented as 1010 9 in binary us 1001 its 1010 | 1001 which means each byte gets to be or so it should be 1 | 1 , 0 | 0, 1 | 0, 0 | 1 1 0 1 1 1011
am i the only one that is now really looking forward to finding out why he goes by ThePrimeagen? even on frontendmasters, while everyone puts their real name on their course, he goes by Primeagen xD
i've got a juicy fact that i just learnt about 5 minutes ago: associative arrays are NOT part of javascript. which leads to some hilarious results below. * if you access an array index using a numerical string, it coerces the string into an int. i.e. *a["420"] === a[420]* * _however,_ if it's not a numerical string it treats it as a property of the object. i.e. *a["07"] !== a["7"]* * all indices where you assigned a value (even if that value is `undefined`) WILL return true if you call hasOwnProperty. i.e. *[6,9,4,2,0].hasOwnProperty("4") === true* and even *[6,9,4,2,undefined,0].hasOwnProperty("4") === true* * if you skip an index, it'll fill the indices in between with empty slots (which is somehow different from assigning `undefined` values) so if you call hasOwnProperty on the in-between indices they'll return false (!!). i.e., if you initialise an array *a = [6, 9, 4, 2]; a[5] = 0;* then *a.hasOwnProperty("4") === false* HOWEVER *[6,9,4,2,undefined,0].every((v, i) => v === a[i]) === true* . wtf?? js isn't just too smart by half, it's too smart by half recursively. it's just unbridled genius all the way down.
@@vitiok78 firstly, that's actually the sort of thing that runtimes are good at making as fast as C, secondly C is slow as deep copies too. Because a deep copy is by definition a lot of work. You could ask for immutable data structures though...
Damn, the stateful regex is a thing straight from a nightmare. If it weren't for TypeScript and it's honestly pretty great type system JS would be nearly unusable.
Write a parser. They're extremely simple, it's a great exercise to do, and they're easily maintainable for almost all situations. The situations in which they don't, there's almost always a library instead of cutting and pasting regex from the internet
It's not fair. Javascript obviously isn't perfect, but every try to replace Javascript fails. to be fair, you should have a 5 reasons to use Javascript BTW maybe Dart on back end can be blazing fast ( do you believe in this comment or you will make your own benchmark and post on youtube ? )
Well, to this I'd simply had the fact that the overall environment is super tedious to master, with all these config files bundling together, which are annoying to master or even understand, the fact that it doesn't really do multi processing "out of the box" and has a super shitty multiprocessing API even now, the callbacks vs promises mess... And yeah mostly the fact that it's used for everything despite being super slow. Also, the fact that it's a language that has a ton of different versions depending on where and how you use it (node VS chrome VS firefox VS mobile etc.), but well this would be a drawback of other languages as well I guess. Also, the fact that the packages are all centralized in one microsoft-owned repo, the fact that a lot of simple and classic libraries have bugs or archaic parts that are like 5 years old sometimes..
Yo prime the foreach gives key value only, if you do Object.entries(OBJECTNAME).foreach((key,value) => console.log(key,value)) am I missing something here ?? Oh it is for map ok sorry I missed that sorry.
@@tinnick we get a array of array of two elments and I am talking about this [ ["key1",value1],["key2",value2]] and you destructure it later for use,so you are technically getting the value of the Parent array which is the child array. So kinda makes sense of value comming first in the case of map.
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
@Emmanuel JS is slow too. Rust, C/C++ and Java are faster than both Python and JS But Python is far superior than JS JS should stick to building UIs, not sure why anyone would wanna do ML in JS