Domanda

JSLint is throwing an error of unused current even though it is used in the while() statement. Obviously my understanding of declaring and using variables is not quite up to scratch. How should I declare and use the variable in this example?

var target,
    myFunc;

target = 8;

myFunc = function () {
    // Declare the function's vars
    var i,
        current;

    i = 0;

    while (i < target) {
        current = i;
    }
}
È stato utile?

Soluzione

Sirko answered the question in a comment but question shows up as 0 answers in the list so I'll add it as answer.

You set the variable but you never use it (read it). Try the following:

while (i < target) {
    current = i;
    console.log(current);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top