DEV Community

Discussion on: Which JS loop is fast?

Collapse
 
suryakant profile image
Suryakant Patil

Hey, Can you test the below For loop? I guess it will give you slightly better performance.

let i=0;
for(; i<10000000000;i++){
  count += i
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
shubhamtiwari909 profile image
Shubham Tiwari

The code is not correct can you please write it correctly

Collapse
 
fjones profile image
FJones • Edited

I'm not sure where you're struggling. The error message is quite telling, in that all that's missing is:

- let i=0;
+ let i=0, count;
Enter fullscreen mode Exit fullscreen mode

Then the snippet runs. Though my quick look over it seems to make it benchmark slower than the for-scoped version, which is a bit surprising.

Thread Thread
 
shubhamtiwari909 profile image
Shubham Tiwari

Yeah got it