Skip to content

Latest commit

 

History

History
33 lines (20 loc) · 594 Bytes

declare-block-scope-variables-with-let.md

File metadata and controls

33 lines (20 loc) · 594 Bytes

Declare block scope variables with let

You're using var to declare variables within a block:

var i, max = 10;

for (i = 0; i < max; i++) {
    var timesLooped = i + 1;
    console.log('Times looped:', timesLooped);
}

Use ES6 let instead:

var i, max = 10;

for (i = 0; i < max; i++) {
    let timesLooped = i + 1;
    console.log('Times looped:', timesLooped);
}

More Information