Search⌘ K
AI Features

Solution Review: Let's Get the Output

Understand how to correctly declare variables in JavaScript using let and avoid errors related to const in changing values. Learn about variable scopes, strictly adhering to safe coding practices with block scope to prevent conflicts in loops. This lesson clarifies how let fits perfectly for independent incrementing in multiple loops, enhancing your ability to write error-free JavaScript code.

We'll cover the following...

Solution

The following is the solution to the problem given in the previous lesson. Let’s review the solution code step by step.

Javascript (babel-node)
'use strict';
function first() {
for(var i = 0; i < 5; i++) {
second();
}
}
function second() {
for(var i = 0; i < 3; i++) {
console.log(i);
}
}
first();

Explanation

First of all, we need to use the use strict directive to reveal the errors. Strict mode ...