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 for loop puts initialization, condition and update together. The initializer runs once. The condition is tested before each body execution. The update runs after the body before the next condition check. An inclusive range starting at one differs from zero-based array indexing. Read these three clauses separately and predict the final value printed.
const end = 3;
for (let i = 1; i <= end; i++) {
console.log(i * 2);
}2 4 6
The inclusive boundary keeps the last requested number in the range.
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 = 1; 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 * 2);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 = 1; i <= end; i++) {
console.log(i * 2);
}2
The inclusive boundary keeps the last requested number in the range.
const end = 1;This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for (let i = 1; 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 * 2);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 = 1; i <= end; i++) {
console.log(i * 2);
}No console output.
The inclusive boundary keeps the last requested number in the range.
const end = 0;This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for (let i = 1; 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 * 2);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 = 1; i < end; i++) {
console.log(i * 2);
}const end = 3;
for (let i = 1; i <= end; i++) {
console.log(i * 2);
}Do not memorize a loop shape without checking what its bounds mean.
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.