JavaScript performance tips | Part 1 #shorts

preview_player
Показать описание
Explanation:
• Each statement in a loop, including the for statement, is executed for each iteration of the loop.
• Statements or assignments that can be placed outside the loop will make the loop run faster.
• Bad code accesses the length property of an array each time the loop is iterated.
• Better code accesses the length property only once outside the loop and makes the loop run faster.

Pls do subscribe and support channel for more videos!
#ExploreJS
Рекомендации по теме
Комментарии
Автор

Reason:
For every iteration of the loop, the following condition is checked
( I < arr.length) i.e you are calculating the value of arr. Length once for every iteration as opposed to computing arr. Length only once and using the variable to compare

abhinavreddyboddu
Автор

Array.length isn't calculated each time you access it, only when the array changes.

Zuaa
Автор

This not make any changes in performance

alagurajmurugan
join shbcf.ru