One fun note: generators are the foundation of async/await syntax. Under the hood, when you create an async/await function, the JS engine creates a recursive generator where all the awaits are converted into yields, and the promises you're awaiting get a .then tacked on which calls the generator's next() method. Without generators, async/await wouldn't be possible :)
@whoman79303 жыл бұрын
where can i learn more?
@spacedoohicky3 жыл бұрын
@@whoman7930 Look up the "co" module. It's on npm. Look at its source on github. That's how it works. The module "co" is a weird early version of doing async/await before async/await existed.
@AlexFord3 жыл бұрын
@@whoman7930 It is rumored that high up in the mountain valley there is a guru. One who has been trained in the ancient arts. The journey is perilous but those who reach him are blessed with the gift of his knowledge. Good luck.
@whoman79303 жыл бұрын
@@AlexFord LOL thank you
@karthikkhoday55553 жыл бұрын
@@AlexFord 🤣🤣
@StevenHoodlebrink3 жыл бұрын
That dynamic import part was mindblowing. I can see it being useful when you're making API calls to refresh the data of an application. There are many instances where the source is only updated weekly or monthly so instead of making API calls with every load. You could do some date checking first and then refresh the data if it is out of date. Great stuff as always Kyle!
@sidharthsid34293 жыл бұрын
Yeah, you're absolutely right ..Great use case
@deonrich31493 жыл бұрын
the curly bracket thing is super cool, never knew that!
@michael69553 жыл бұрын
Same xD
@TheRealCAPerry3 жыл бұрын
Also same
@lawrencedoliveiro91043 жыл бұрын
It’s a standard feature of block-structured languages, like C. Which in turn copied it from old Algol.
@bennymeister3 жыл бұрын
I've used that with switch statements for a while, just never thought why it worked :)
@KasuraIchimaki3 жыл бұрын
me neither... super weird that you could use brackets like that
@miku4j3 жыл бұрын
“Example isn't another way to teach, it is the only way to teach." - A. Einstein
@chrisual3 жыл бұрын
'98% of A. Einstein quotes were not said by A. Einstein' - A. Einstein
@sovietbot67083 жыл бұрын
Fun fact: Einstein was a socialist who supported the Soviet Union. I'm not using the word socialism the way right wingers use it. I mean he literally called himself a socialist. He even wrote a book called "Why Socialism"
@NickoSinclair3 жыл бұрын
Cool video, just a slight bugbear of mine: doesn't make it more semantic, if anything you made it less semantic. Stick with in that context. Strong doesn't simply make the text bold, it strongly emphasizes it.
@CodingNuggets3 жыл бұрын
Glad you're continuing on with these. Definitely learning a thing or two that I didn't know. Much love as always Kyle. See you soon!
@88spaces7 ай бұрын
I've been watching videos of JS things I've never heard of, and the dynamic import feature blows me away. This is truly a game changer.
@danvindsouza27253 жыл бұрын
Nice Video Kyle! Enjoyed it like most of them! 5:40 The in operator also looks at the prototype chain. Using object_name.hasOwnProperty(property_name) will search only for that property within the object. But in operator will search for the property within the object and if not found will search the prototype chain. In certain cases we need to consider that.
@patrickc.61833 жыл бұрын
Dynamic imports are a very cool feature! Definitely useful, but not well known 👍.
@lawrencedoliveiro91043 жыл бұрын
Interesting that, in Python, all imports are dynamic; you can put a regular “import” statement inside a function or class if you want.
@xXYourShadowDaniXx3 жыл бұрын
That id generator example was great, very intuitive use case!
@christophalbrecht10883 жыл бұрын
Loving it! supposedly simple things like scopes open up completely new possibilities. Thx for your videos I'm always inspired
@vincentjohnflorio3 жыл бұрын
I get ragged on constantly for talking too fast; once I taped a kind of infomercial and they needed four takes at one point to get useful footage because even me purposely slowing myself down left them clueless at how to make me clearly enunciate. So I really appreciate that I can hear and understand you perfectly fine at 2x speed. It saves me time but also means that you're not losing people like I am with my meandering babble speed.
@liondeluxe38343 жыл бұрын
Template literal functions is really useful. I wish I knew before because I can now use it to sanitize user generated inputs for dynamically rendered content
@AlexFord3 жыл бұрын
In the generator you could have just done `yield id++` since the ++ executes after the yield statement. You probably already know this but just in case, you can also reverse that syntax (`yield ++id`) to ensure the ++ executes *before* the yield statement :)
@reyanrahman3 жыл бұрын
U always comes up with something new every time
@WeaselBass3 жыл бұрын
Those are some awesome things I'm going to immediately forget the next time I have to write any JavaScript...
@brhh3 жыл бұрын
press Y for S ame
@szpaklabs88933 жыл бұрын
great examples! finally I understood the purpose of the generator functions. dynamic import is also very useful, thank you!
@Nyco3D3 жыл бұрын
Best advice is the dynamic module import, life saver!
@IkraamDev3 жыл бұрын
I'm currently working on a Todoist clone and I never use Switch Statements, but when you mentioned it, I was literally working on a perfect part of the app to add a Switch Statement!
@Rodo18022 жыл бұрын
I cannot get enough of your knowledge and clarity. You are a saviour in all its dimension!
@88spaces7 ай бұрын
Generator functions are new to me. I'm glad you covered this.
@tajuddinkhan52063 жыл бұрын
It's just amazing that you are able to explain these concepts so easily.
@brhh3 жыл бұрын
such an amazing teacher isn't he!
@clevermissfox5 ай бұрын
5:09 could this "in" keyword work in a ternary where the check is for the key not the value ? "name" in person ? "Has name property" : "no name property"
@tezdogs3 жыл бұрын
I only started writing JavaScript about 2 or 3 months ago and these videos are absolute gold! Liked, subscribed, and a comment for the algorithm. Keep up the great content man! Love your work
@ro19423 жыл бұрын
Wow the generator function knowledge blew my mind out of the back of my head and through the drywall into the garden! Insanely useful , thank you Kyle!
@duanemcdonald69603 жыл бұрын
Kyle, you are so effective, helpful and concise. Please don't stop.
@dabbopabblo2 жыл бұрын
For years now Ive been appending scripts to the body and listening for their load event, realizing import() is a thing is a literal game changer
@jaideepshekhar46213 жыл бұрын
For the template literal functions, I prefer them like this: const user_profile = (firstName, hobby) => `
@kitsunekaze933 жыл бұрын
5:45 "cant do any other way" can do: *if ( person.hasOwnProperty('name') )* also userful for stuff like: for ( let key in array ) can also loop over the values: for ( let val of array )
@chlbri2 жыл бұрын
the "in" keyword to validate an object is awesome
@nfarruggia3 жыл бұрын
Your videos are insanely helpful! Keep it up!
@MrBroady023 жыл бұрын
I like to click these on the off case that I may learn something. Today I learned 3 things. Nice work!
@sapindersingh11653 жыл бұрын
Kyle definitely knows what things I'm ignorant of. That's why he pushes my javascript level further every time.
@patcodingcodester97813 жыл бұрын
DUDE the curly brackets thing comes up with me using state management. the reducer switch statements always got me with this. I'd end up having the most dumb names for new objects and arrays because my naming convention was always impacted. So clutch!
@jojok4272 жыл бұрын
Dang, how did I not know half of these... this was incredibly helpful! Thank you!
@rachidb96242 жыл бұрын
Generator function looks interesting, first time hearing about it, thanks mate !
@allthingsdev40713 жыл бұрын
Thanks for explaining things to people whom have little prior coding experience. Every detail counts
@christianfreund20393 жыл бұрын
Hi Kyle, I was mesmerized when you moved the brackets down in the switch-statement example. Can you show how you did that? Or even better: Wouldn't it be a nice topic for a video? Keyboard tricks for faster work in VS Code
@sesho7773 жыл бұрын
You are the best at explaining confusing stuff in a simple way, thanks man!
@Gigatless3 жыл бұрын
That's pretty sick bro good job. Can you make a vid about what a starting JS programmer can do between finishing a course/writing his first app and finding a job? Talking about finding a way to apply skills and maybe making some money along the way. Someone mentioned contributing to real projects on github but I can't find that video and how to do it.
@Californ1a3 жыл бұрын
For contributing to projects on github, check out CodingGarden's "How to Contribute to Open Source Projects" video. It's a livestream past broadcast, about 3 hours long, but he goes through the entire process of finding a project, going through all their contribution guidelines, finding an issue to work on, cloning the repo, running the tests, reproducing the issue locally, and tracking down the cause of the issue plus a little bit of trying to fix it.
@Gigatless3 жыл бұрын
@@Californ1a thanks!
@nitsanbh3 жыл бұрын
“When you have a specific use case for them, they are really useful” Well I can’t say that’s untrue
@brhh3 жыл бұрын
out of all the ways you could've said false, you chose the one that doesn't relate to programmers, F
@sohammondal5782 жыл бұрын
Wow so much content in just 20 mins. Brilliant. ❤️
@CotyCondry3 жыл бұрын
these are really good, I think I actually understand generators now.
@michakwasiuk17313 жыл бұрын
You are awesome kyle! Looking forward to your javascript course!!
@HorstKirkPageKian2 жыл бұрын
Regarding the first example about block statements. While nothing you say is wrong, sometimes it's a case of "Just because you can, doesn't mean you should". The part about "redeclaring" variables in a new scope with the same name as in the outside scope does work, yes, but once you start to think in the direction of Clean Code it's not necessarily good practice. Because it actually makes it a teeny tiny bit harder to understand that code for outsiders/other maintainers of that code. There is even an eslint rule that checks that. But the rest of the video and your examples were very good, thanks!
@ritudey85203 жыл бұрын
Love your explanations. Simple, short and clear. Thanks🤍
@JimRooney3 жыл бұрын
Always such quality content! Love your work mate.
@yeahyeahduderooski3 жыл бұрын
Love the import() info at the end! Our pages are full of stuff so this will help speed up the code our team owns
@scheimong3 жыл бұрын
The generator function in JavaScript is semantically similar to the concept of "lazy iterator" in other languages, in particular Rust. I'm mentioning Rust by name because it's not until I learned this language that I was able to fully appreciate how powerful iterators can be.
@elmyllo42193 жыл бұрын
me see the thumbnail: "hey.. I know that one" also me start watching the video: "wha-- "
@raellawrence71163 жыл бұрын
Same. I think I'm quite knowledgeable in this area, but then I find 2 things in this video that can improve my code right away.
@letieuanh86982 жыл бұрын
That Generator explanation is god damn helpful with me, thanks!
@spangler7362 жыл бұрын
I’m confused what the last template literal function example is doing. It doesn’t seem to be utilizing anything with template literals and seems like it could just be a regular function, right?
@rejinraghavan76163 жыл бұрын
Hey Kyle.. Came across your videos recently.. I really like it.. It's concise and informative.. :)
@DaggieBlanqx3 жыл бұрын
Wow! Just wow! Nothing more... just another wow!
@mohannadize3 жыл бұрын
I have seen and used the tagged template literal syntax in developit/htm and have always wondered how it works but i didn't find the docs for it. Thank you so much for the tips! ♥️
@sephstar-offical2 жыл бұрын
2:37 How you do thiat? Is it Ctrl+Arrows(Up/Down)
@exodustx03 жыл бұрын
Might have been useful to point out that generator functions can be iterated through with a for-of loop too. That's easily my favourite way of using them.
@lawrencedoliveiro91043 жыл бұрын
3:33 So since you cannot define the same constant along multiple branches of a switch, what happens if you define it in one branch and reference it in another branch? Will you get the defined value?
@dealloc3 жыл бұрын
Depends; if the branch is fallthrough, as in you don't have a break or return between one branch and another. As long as it's accessible by a branch it will be accessible. However, if you try to use `const` or `let` variables in an inaccessible branch (e.g. non-fallthrough) it will throw an error, since the variable isn't accessible when that branch is executed. It's often best to always scope your statements, even if you don't rely on this, in order to avoid unexpected behaviors.
@ianterada68213 жыл бұрын
The template literal section was really interesting!
@jimmyj.67923 жыл бұрын
Awesome tips discovery. Thanks a lot for this 👌
@rustygear4473 жыл бұрын
3:04 what's the shortcut to move the closing bracket down the lines? I need that Edit: nvm, I found it! just Alt + Arrow lol
@jeremyfiel3 жыл бұрын
If you highlight you code block and then type the bracket you want to use it will wrap it for you rather than worrying about moving the bracket around manually
@HughMacLeod423 жыл бұрын
I jumped when I saw this magic too! He used it elsewhere. I searched the comments before begging for this trick. Thanks for posting. :)
@avi123 жыл бұрын
Back in the day, when I was using switch statements, I put the { } because I thought they were necessary, as I came from C# and I've seen switch statements with { } for each case Thanks to you, I realized it works because each { } block is basically a nested scope
@DewieTheBard3 жыл бұрын
I watched the last video and a few days later I used one of those features. Thank you for making great content
@ganeshbabu64583 жыл бұрын
Your channel is awesome. Keep us educated as usual👍
@zombiefacesupreme2 жыл бұрын
Man, Kyle must really like bowling, weightlifting, and playing guitar.
@stoneshou3 жыл бұрын
this is so good! right on point when i'm looking for a way to postload some modules.
@johnkeck3 жыл бұрын
Great stuff! Thanks so much!
@nept11872 жыл бұрын
INCREDIBLE FOR DYNAMIC IMPORTS
@lawrencedoliveiro91043 жыл бұрын
17:22 But that will slow down the response to the click that causes the module import. And if the import is local to the event listener, then it will be discarded after every call, and need to be reimported on the next.
@dealloc3 жыл бұрын
That is a compromise you make based on your needs. Sometimes it's better to lazily load some code, rather than upfront which can have advantages in performance and load times, compared to static imports. Other times, it's not worth it-it depends entirely on your situation. Also keep in mind that importing won't need to re-import the source once it's already been loaded. The browser is smart enough to cache imported modules (also dynamically imported ones). If you'd like to re-import something, you can always attach a query parameter to your import string with a unique string, although this is not recommended.
@graemekalb22923 жыл бұрын
DEFINITELY using the in keyword, thank you!!
@i3looi23 жыл бұрын
Berry nice. I think I have a use for the generator function in one of my projects. Also the dynamic imports. Thanks.
@mybluemars3 жыл бұрын
Hi Kyle, I just wanted to say that your logic and teaching style is very good, and I am not a programmer!
@lawrencedoliveiro91043 жыл бұрын
11:55 However, note that “yield” is actually an expression, not a statement.
@KangJangkrik3 жыл бұрын
Like typeof and instanceof?
@lawrencedoliveiro91043 жыл бұрын
Well, those don’t do anything useful apart from returning values, whereas yield does transfer of control as well.
@artgreg22963 жыл бұрын
Thanks Kyle. I was knowing all of them. Did you mention delegator generator?
@mainendra3 жыл бұрын
Awesome 👏. I wish KZbin allow multiple thumbs up 👍
@rosem50623 жыл бұрын
One thing about block scope ({} scope), if nobody has mentioned it yet: Only variables defined with let and const are restrained to a block scope. Variables defined with var are not. Var variables will leak from for loops, if statements, or any other block scope (but not function scopes) while let and const variables will behave as demonstrated in the video.
@anonymously943 жыл бұрын
And here I was, thinking I knew all there was to JavaScript. Silly me. Thank you for sharing. Very helpful
@ms77grz3 жыл бұрын
That curly braces thing is so called block scope in JS (ES6) scoping and applies to variables declared via const and let. Functions are also block scoped (in strict mode)
@lawrencedoliveiro91043 жыл бұрын
10:54 Isn’t the reduce call basically achieving nothing at this point? Remove that, and the body of queryAll becomes just the “return querySelectorAll” call, and the only difference between that and a regular function call is that you have omitted the parentheses around the argument. Which doesn’t seem very useful.
@hamidmohamadi29433 жыл бұрын
Great kyle as always. Thanks a lot
@HuoShengChiou3 жыл бұрын
This video gives me new knowledge. Thank you
@HakunaMatata-it2qr3 жыл бұрын
I love this feature series..!🔥🔥
@sarwankumar53392 жыл бұрын
I liked the one about dynamic import and checking if a property exists in an object
@sarwankumar53392 жыл бұрын
Is going to use this in our project
@BrandonNozakiMiller3 жыл бұрын
I am impressed with your knowledge of archane JS. I didn't know one or two of these.
@aashiqahmed52733 жыл бұрын
dynamic import are dope man
@devrxt103 жыл бұрын
thanks for this video. keep making videos like this
@AlanD203 жыл бұрын
WOW, that's amazing :) I feel like the generator function is pretty useful for building a linked list or binary trees and other algorithms. definitely makes thing easier.
@Lokus1223 жыл бұрын
I think It would also fit nicely to create some loading screen with progress bar if function takes a lot of time
@axiezimmah3 жыл бұрын
yield is actually something I did not know. nice
@Tuuhwix3 жыл бұрын
Time to refactor my code! For the dynamic module import. I recently had to use require() because I wanted to put a template literal based on the name of file. But now I think I'm going to change it to the way you showed us 🙂 My example: for (const file of myFiles) { const myModule = require(`./foldername/${file}`).default // more code done with myModule... }
@ehtishamtahir21873 жыл бұрын
That curly bracket trick👌👌👌
@Really124 Жыл бұрын
Isn't using curly braces usseccery in the switch case?(as you can declare the varuable before the switch?)
@ngneerin3 жыл бұрын
You could use continue instead of if block
@devashishbahri33533 жыл бұрын
Can you please tell which extension of VS Code are you using which is dynamically striking through code and also graying out condition statements if they are false?
@SergeofBIBEK2 жыл бұрын
I've used the template literals to handle adding the optional s based on the count. Pretty clean compared to some ternary if or something in the string itself.
@stanislavmalyshev52093 жыл бұрын
Top content! Thank you :)
@techstuff22373 жыл бұрын
That was the simplest explanation of generator functions!
@nickolaizein74653 жыл бұрын
I want to see more real examples of generator usage. Id generator is too easy. I always try to use generator in my project (for study purposes), but I don't find a prefer place for it. More examples are glad. Thanks!