for (let i = 0; i < n; i++) gives full control over counting — ideal when you need the index or a non-trivial step. Use let (not var) so each iteration scopes i correctly, especially with closures/timeouts inside the loop.
for (let i = 0; i < n; i++) gives full control over counting — ideal when you need the index or a non-trivial step. Use let (not var) so each iteration scopes i correctly, especially with closures/timeouts inside the loop.
<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const sq=[]; for(let i=0;i<5;i++) sq.push(i*i);
document.getElementById('o').textContent=sq.join(' ');</script></body></html>▶ Open the interactive comic issue