我有以下用于测试的代码块:
var readyToGo = false;
readyToGo = true;
console.log(readyToGo); // reads "true" in console
if(readyToGO === false){ // also tried readyToGO == false (that fails too)
console.log('not ready');
return false;
} else {
alert("true, and we're done!");
}
问题是,控制台显示:
true
ReferenceError: readyToGO is not defined
为什么会出现参考错误?我错过了什么?
答案 0 :(得分:4)
JavaScript区分大小写,readyToGO
中有一个大写的O,更改为:
if(readyToGo === false){
// ^ use lowercase o not O
答案 1 :(得分:0)
您的变量名为readyToGo
,而不是readyToGO
。将支票更改为:
if(readyToGo === false){ // also tried readyToGO == false (that fails too)
答案 2 :(得分:0)
readyToGO - 拼写错误。应该准备好了吗