Chrome freezes/ crash when is try to open my index.html

So I'm writing some JS in VS and when is try to open my browser to see the console, everything freezes and crash. Does anyone have any idea why this happens. All help needed, thanks!
6 Replies
rayaqin
rayaqin12mo ago
Hi Could you paste in your JS code here? In the #how-to-ask-good-questions guide you can find the right way to format code. Most likely you have an infinite loop going there somewhere. Maybe a while loop?
filipniik
filipniik12mo ago
Okey, thanks!! Just deleted the loop code and it works now. Do you mind explaining what is going on? for(let rep = 1; rep <= 10; rep = rep++) { console.log(Lifiting weights rep 1 ${rep}); } Where did I go wrong? I found it, No worries thanks a lot!!
rayaqin
rayaqin12mo ago
you do rep = rep++ instead of rep++ ah okay
filipniik
filipniik12mo ago
just saw it, thanks man!
rayaqin
rayaqin12mo ago
Since you've encountered this issue, I think it might be worth it to take a second look and understand why the code didn't work exactly. Take this for example:
let a = 1;
a = a++;
console.log(a);
let a = 1;
a = a++;
console.log(a);
What would you expect to be logged to the console here, and why? The ++ operator increases the value of the variable by 1, but the whole expression a++ evaluates to the original value of a, which is 1, meaning a = a++ will in the end reassign a's value to be 1, after increasing it by 1.
Jochem
Jochem12mo ago
variable++ is often called the post-increment operator. There's also a pre-increment operator, which would be ++variable which is rarely used. In general, you only use variable++ in isolation, either in the third argument in a for loop, or as a counter increments, and save yourself the hassle of having to think about when the value actually changes.
Want results from more Discord servers?
Add your server