+ 8
Var i is in a loop that adds 1 while i is smaller than 9. On the last iteration, where i = 9, it adds 1 for a last time and the loop ends.
The "i++" part is executed once more after the condition is false.
+ 8
Basic for loop runs until the condition is met
i=0; i < 10; i++
Inside the loop i will reach 9
Outside the loop i will be 10
You can test that with the following code:
for (var i = 0; i<10; i++) {
console.log("value of i inside loop: " + i);
}
console.log("value of i outside of the loop: "+ i);
The following part of your code won't work:
for (let j = 0; j<10; j++) {
}
console.log(j);
Reason:
let is block scoped and is "invoked" inside the curly brace and cannot be called outside of it
You can fix this by making let scope to entire window (global? Sorry I'm a java nerd)
//declare j outside of the for loop scope
let j;
for (j = 0; j < 10; j ++) {
}
console.log (j);
Also a friendly reminder - for loops without body exist! (at least in java 😝)
for ( var x = 0; x < 10 ; x++); //no body in this loop
console.log(x);
Output: 10
+ 4
SainPro 🤝
It is still a good attempt to help answering in Q&A, because it pushes us to do revision / search to learn knowledge.
Look forward to seeing more contribution from you 💪
+ 3
SainPro No, only const is not changeable. Variables declared with let keyword is changeable.
The reason for ReferenceError is because variables declared with let is block-scoped.
See this lesson which explained very well:
https://javascript.info/var
+ 2
Because... 😊
while(i < 10){
// output i and THEN increment 1
console.log(i);
i++;
}
output: 123456789
while(i < 10){
//increment 1 THEN print
i++:
console.log(i);
}
Output:12345678910
+ 2
Console.log(i) or console.log(j) must be inside the loop , not outside the loop. Outside the loop, there is no scope of i and j
+ 1
console shoud be inside the loops
0
Please I need more explanation on JS computed property names
0
Help me please



