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
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?
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!!you do rep = rep++ instead of rep++
ah okay
just saw it, thanks man!
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:
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.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.