-2

How to declare an iterator for loop variable that passes JSLint.com validation.

I have tried var, let, and neither work. I simplified my script down to this line. JSlint.com will not progress past this warning. Have googled it and tried every combination of for loops I can thing of. I have enabled allowing for loops, and read the JSlint nazi help guide.

/*jslint
 for
*/
function test() {
    "use strict";
    for (let i = 0; i < 5; i += 1) {
        console.log(i);
    }
}

JSLint.com flags:

Unexpected 'let'.
    for (let i = 0; i < 5; i += 1) {

This is not an unused variable problem. To prove it, I changed it to console log i, the only variable, it gives the same error, whether in strict mode or not.JSLint does support ES6

run_the_race
  • 1,344
  • 2
  • 36
  • 62

1 Answers1

1

accordingto JSlint http://www.jslint.com/help.html#for JSLint does not recommend use of the for statement. Use array methods like forEach instead. The for option will suppress some warnings. The forms of for that JSLint accepts are restricted, excluding the new ES6 forms. edit : this works if you enable for

function test(){
let i = 0;
for (i = 0; i < 5; i += 1) {
       console.log(i);
    }
}
  • Thank you, that was the root cause! Took a little more tweaking to completely. function test() { "use strict"; let i; for (i = 0; i < 5; i += 1) { window.console.log(i); } } – run_the_race Jan 30 '19 at 17:17