Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Curious about why i becomes 5 in the end?
for (var i = 0; i < 5; i++) { console.log('A: ', i); } console.log('B: ', i);
i = 4
i < 5 === true
console.log('A: ', i);
i++
i = 5
i < 5 === false
i++ increases the value of i at the end of each loop.
i
The loop goes round until the condition (that i is 4 or less) isn't true.
When i is 5, that is the first time the condition isn't true.
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
i = 4->i < 5 === true->console.log('A: ', i);->i++->i = 5->i < 5 === false-> end loop.