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 nested loop runs an inner repetition for every outer iteration. The total amount of work can grow as the product of the two bounds. Here each row contains a repeated character, making the relationship visible without adding arrays yet. Keep the two counter names distinct. Very large bounds can make a small-looking program expensive, which is why the practice examples stay deliberately small.
const size = 3;
for (let row = 0; row < size; row++) {
let line = "";
for (let column = 0; column < size; column++) {
line += "*";
}
console.log(line);
}*** *** ***
Each of size rows contains exactly size symbols because both bounds are exclusive.
const size = 3;Declare size with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
for (let row = 0; row < size; row++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
let line = "";Declare line with let. The binding may be reassigned later. The expression after = supplies its initial value; = is assignment, not an equality comparison.
for (let column = 0; column < size; column++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
line += "*";Execute this statement at this point in the program. The update changes the current binding or object; compare state before and after.
}Close the current instruction block.
console.log(line);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 size = 1;
for (let row = 0; row < size; row++) {
let line = "";
for (let column = 0; column < size; column++) {
line += "*";
}
console.log(line);
}*
Each of size rows contains exactly size symbols because both bounds are exclusive.
const size = 1;This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for (let row = 0; row < size; row++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
let line = "";Declare line with let. The binding may be reassigned later. The expression after = supplies its initial value; = is assignment, not an equality comparison.
for (let column = 0; column < size; column++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
line += "*";Execute this statement at this point in the program. The update changes the current binding or object; compare state before and after.
}Close the current instruction block.
console.log(line);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 size = 0;
for (let row = 0; row < size; row++) {
let line = "";
for (let column = 0; column < size; column++) {
line += "*";
}
console.log(line);
}No console output.
Each of size rows contains exactly size symbols because both bounds are exclusive.
const size = 0;This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
for (let row = 0; row < size; row++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
let line = "";Declare line with let. The binding may be reassigned later. The expression after = supplies its initial value; = is assignment, not an equality comparison.
for (let column = 0; column < size; column++) {Initialize the counter once, test its condition before each iteration, and update it after the body. Track the boundary carefully.
line += "*";Execute this statement at this point in the program. The update changes the current binding or object; compare state before and after.
}Close the current instruction block.
console.log(line);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 size = 3;
for (let row = 0; row < size; row++) {
let line = "";
for (let column = 0; column <= size; column++) {
line += "*";
}
console.log(line);
}const size = 3;
for (let row = 0; row < size; row++) {
let line = "";
for (let column = 0; column < size; column++) {
line += "*";
}
console.log(line);
}Name counters by their meaning, such as row and column, rather than reusing i in nested scopes.
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.