So jsLint says my x is not defined. I looked it up everywhere but I cant find how to define it...
jsLint说x没有定义。我到处都找过了,但是我找不到如何定义它……
for (x = 0; x < verdachten.length; x++) {
console.log("De verdachte is de " + verdachten[x].leeftijd + "jaar oud " + verdachten[x].naam + ", de " + verdachten[x].wie);
}
That's where it goes wrong. The x...
这就是问题所在。x……
2 个解决方案
#1
2
This is a case of jsLint being a bit overcautious. Most browsers will automagically define the x
, but jsLint warns of this as it's easy to get a scoping bug if you don't properly init your variables, like this:
这是jsLint有点过于谨慎的例子。大多数浏览器将自动定义x,但jsLint对此提出警告,因为如果不正确初始化变量,很容易出现一个范围界定错误,如下所示:
for( var x = 0; x < verdachten.length; x++ ) {
console.log(
"De verdachte is de " +
verdachten[x].leeftijd +
"jaar oud " +
verdachten[x].naam +
", de " +
verdachten[x].wie
);
}
Problems can arise if you have an x
defined somewhere else within scope:
如果x在范围内的其他地方被定义为:
function doStuff() {
var x = "derp";
// things
console.log(x); //=> "derp";
for(x = 0; x < 100; x++) {
// other things
console.log(x);//=> 0..99
}
console.log(x); //=> 99
// original x variable has now changed :(
}
#2
0
for (var x = 0; x < verdachten.length; x++) {
console.log("De verdachte is de " + verdachten[x].leeftijd + "jaar oud " + verdachten[x].naam + ", de " + verdachten[x].wie);
}
for (var x = 0; x < verdachten.length; x++) {
对于(var x = 0;x < verdachten.length;x + +){
You have the problem in defining the variable 'x'. In javascript variables are defined by prefix var and do not require variable type.
在定义变量x时遇到了问题。在javascript中,变量由前缀var定义,不需要变量类型。
Happy Programming :)
编程:快乐)
#1
2
This is a case of jsLint being a bit overcautious. Most browsers will automagically define the x
, but jsLint warns of this as it's easy to get a scoping bug if you don't properly init your variables, like this:
这是jsLint有点过于谨慎的例子。大多数浏览器将自动定义x,但jsLint对此提出警告,因为如果不正确初始化变量,很容易出现一个范围界定错误,如下所示:
for( var x = 0; x < verdachten.length; x++ ) {
console.log(
"De verdachte is de " +
verdachten[x].leeftijd +
"jaar oud " +
verdachten[x].naam +
", de " +
verdachten[x].wie
);
}
Problems can arise if you have an x
defined somewhere else within scope:
如果x在范围内的其他地方被定义为:
function doStuff() {
var x = "derp";
// things
console.log(x); //=> "derp";
for(x = 0; x < 100; x++) {
// other things
console.log(x);//=> 0..99
}
console.log(x); //=> 99
// original x variable has now changed :(
}
#2
0
for (var x = 0; x < verdachten.length; x++) {
console.log("De verdachte is de " + verdachten[x].leeftijd + "jaar oud " + verdachten[x].naam + ", de " + verdachten[x].wie);
}
for (var x = 0; x < verdachten.length; x++) {
对于(var x = 0;x < verdachten.length;x + +){
You have the problem in defining the variable 'x'. In javascript variables are defined by prefix var and do not require variable type.
在定义变量x时遇到了问题。在javascript中,变量由前缀var定义,不需要变量类型。
Happy Programming :)
编程:快乐)