Ready. Start with one instruction.
Loading the learning workspace…
FROM YOUR FIRST INSTRUCTION TO A WORKING APPLICATION
Learn JavaScript from scratch through small working examples, visual experiments and complete projects. No account or AI key required.
Predict → Experiment → Build → Test → Explain
Ready. Start with one instruction.
Loading the learning workspace…
A loop repeats a set of instructions while a condition remains true. The repeated body should make progress toward stopping. A simple counter lets you see exactly which iteration is running. Loops are useful for repeated work, not merely printing numbers. They can also hang a program if the stopping condition is never reached, so our worker has a strict execution limit.
const end = 3;
for (let i = 0; i < end; i++) {
console.log(i);
}0 1 2
The strict upper bound runs indexes zero through end minus one and runs zero times when end is zero.
const end = 3;Declare end with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
for (let i = 0; i < end; i++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
console.log(i);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
}Close the current instruction block.
const end = 1;
for (let i = 0; i < end; i++) {
console.log(i);
}0
The strict upper bound runs indexes zero through end minus one and runs zero times when end is zero.
const end = 1;This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for (let i = 0; i < end; i++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
console.log(i);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
}Close the current instruction block.
const end = 0;
for (let i = 0; i < end; i++) {
console.log(i);
}No console output.
The strict upper bound runs indexes zero through end minus one and runs zero times when end is zero.
const end = 0;This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for (let i = 0; i < end; i++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
console.log(i);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
}Close the current instruction block.
Repair the intentionally changed operation so the example produces the exact expected result. Then try the extension without copying the answer.
const end = 3;
for (let i = 0; i <= end; i++) {
console.log(i);
}const end = 3;
for (let i = 0; i < end; i++) {
console.log(i);
}Check zero iterations and one iteration when testing a loop.
Which operation changed the result, why did it work, and what would you test next?
Use a different value that could expose a boundary or mistake. Predict the result first, run it, and explain how the concept would help in a small real application.
Related: Previous lesson Next lesson
100 lessons across 20 modules, covering variables, operators, strings, conditions, loops, functions, scope, arrays, objects, DOM, events, state, testing, asynchronous JavaScript and application development.