14.
The for of Loop
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
6 Comments
You can absolutely use const instead of let in "for of" loop.
Hey plashenkov!
Ah, you're totally right! It's not something I had even thought of - const isn't allowed for a traditional "for", but definitely is for "for of". Thanks for the note!
Cheers!
In _mapErrorsToForm the `return` should be `continue`. With `return` the loop will stop iterating after first valid form input as the method executions is finished.
Hey @Marcin!
Ah, you’re totally right! I’ll have is update that so it doesn’t mess anyone up.
Thanks for reporting this!
Hey @Marcin
Actually, in order to stop the loop you have to specifically return
falseotherwise the return statement will work just as acontinuestatementFrom jQuery docs: "You can stop the loop from within the callback function by returning false."
Hey MolloKhan!
Yes..... but unfortunately, in this case, we're not using a jQuery loop :). This is a native, JS
forloop. So, the return will exit from the _mapErrorsToForm function. But, I know why you got confused! This function did originally use a jQuery loop (https://symfonycasts.com/screencast/javascript/js-validation-error-handling#codeblock-f4b4af62c2). At some point, we refactored it to a native for. And that is when we needed to also change that return statement.Cheers!
"Houston: no signs of life"
Start the conversation!