简体   繁体   English

JSLint抱怨在while()语句中使用未使用的变量

[英]JSLint complaining of unused variable when it is used in a while() statement

JSLint is throwing an error of unused current even though it is used in the while() statement. 即使在while()语句中使用了JSLint,它也会引发未使用current的错误。 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;
    }
}

Sirko answered the question in a comment but question shows up as 0 answers in the list so I'll add it as answer. Sirko在评论中回答了该问题,但问题在列表中显示为0个答案,因此我将其添加为答案。

You set the variable but you never use it (read it). 您设置了变量,但从未使用过(读取它)。 Try the following: 请尝试以下操作:

while (i < target) {
    current = i;
    console.log(current);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM