JavaScript for-loops are… complicated - HTTP203

preview_player
Показать описание
In this episode, Jake and Surma dissect how for-loops actually work and how they’ve evolved. Turns out, it got complicated.

Рекомендации по теме
Комментарии
Автор

I’m just waiting for the next big data leak to be the result of a for loop vulnerability.

Автор

The discussion and topic is great. If it had some console.log results shown I would have been more easily following the discussion.

Norfeldt
Автор

Super interesting but I have one complaint - I wish you would take care to show the screen for longer periods and more often. Especially when one of them is actually pointing at the screen explaining stuff and you're still on their faces so we can't even see what part of the code they are referencing. Showing their faces helps break up video in a pleasing way but it provides no education value.

lb
Автор

"If you format your code like this I'm gonna slap you." 😂

DebabrataAcharya
Автор

JavaScript is very good at making simple things become complex, for simplicity purposes...

StarCoreSE
Автор

It was cool. I missed valuable videos like this one.

AlekseyNew
Автор

videos like these make me want to unlearn programming

girlswithgames
Автор

Not so much that for-loops are complicated, more that closures and scoping is complicated.

mikehallishere
Автор

Thanks to you, I found that eval('for(let i=0; i<1; i++) { 42; }') actually *returns* 42

kosnk
Автор

I gotta say, i thought this was going to make my brain implode, and it did but not as much as i expected it to. gj jake and surma

AndrewLuhring
Автор

Really complicated ::: Oh God! Jake and Surma... That was a really helpful one. Thanks :)

sreelalts
Автор

This channel is like Numberphile for web developers

ElektrykFlaaj
Автор

I am not sure if I should be worried that none of this surprised me, except the fact that update check is considered to be the start of the iteration.

LA-MJ
Автор

I recently stumbled upon this bit of info (from Kyle Simpson IIRC) which talked about function parameters having their own context and stuff. I was wondering since there is a new `for await` syntax and generators and all kinds of things, could we have like a whole redo on "scope, contexts and closures" with all the ES* features and the under-the-hood on how these concepts are different now? Would love to see that on this series or in some other form on this channel.

sangeeth
Автор

I use bare blocks (thanks for the name), in both Javascript and Java.. Very useful to help setup a variable you want to keep but throw away the helping variables (or in most cases, use the same named variable but with different types)

ColinRichardson
Автор

Meine Güte! Da wird die Wartung von fremdem Code noch ein Stück "lustiger" :O

karlheinzneugebauer
Автор

Interesting stuff..just one thing, make sure the presentation of the code LAST LONGER on the video and also highlight the part with red circles when he is pointing to a specific part of the code..

slavkokovljenic
Автор

1:52 - I should have known Jake would pull out "setTimeout". That's like your thing now, isn't it? Jake "the Event Loop" Archibald presents... :-)

wmhilton-old
Автор

The var vs. let setTimeout examples can be really confusing.

If the presenters showed the ES5 version of the code, it would make a lot more sense especially to the beginners.

I used webpack to transpile the ES6 version source code to ES5.

ES6:

for ( let i = 0; i < 2; i += 1) {
setTimeout(() => {
console.log(i);
}, 0);
}


Becomes ES5:

var _loop = function _loop(j) {
setTimeout(function () {
console.log(j);
}, 0);
};

for (var i = 0; i < 2; i += 1) { _loop(i); }


In ES5 code, we are invoking the _loop() function during each of the for-loop iteration.

Because the _loop() function is invoked with the value of i, therefore the value of i is copied to the new lexical scope which is created by the _loop() function.

Eventually the function setTimeout() is invoked inside the lexical scope of the _loop() function where the variable j holds the copied value of i.

jasonguo
Автор

cool stuff. essentially multiple {} zones in for loop's ()

pdcx
join shbcf.ru