问题描述
183| });
184|
>> 185| <% if(just_registered) { %>
186| alert("Welcome!");
187| <% } %>
188|
just_registered is not defined
基本上,我想说:if just_registered已定义且为真,然后是警报。但是,我想要将所有内容设置为false ...我只想保留未定义(我有100个变量)
Basically, I want to say: if just_registered is defined and is true, then alert. However, I want want to set everything to false...I just want to leave it undefined (i have like 100 variables)
推荐答案
<%if(typeof just_registered!==undefined){%>
基本上你的检查是否存在局部变量。为此,您必须使用 typeof
运算符,因为访问 just_registered
这是一个未声明的局部变量会创建一个引用错误。
Basically your checking whether a local variable exists. To do this you have to use the typeof
operator since accessing just_registered
which is an undeclared local variable creates a reference error.
这是最好的
var foo;
if (foo) { }
vs
//var foo;
if (foo) { } // ReferenceError
其中
//var foo
if (typeof foo !== "undefined") { }
可行,因为使用typeof运算符访问未声明的变量只返回undefined
而不是抛出a ReferenceError
Will work because accessing an undeclared variable with the typeof operator just returns "undefined"
rather then throwing a ReferenceError
这篇关于如何在node.js中停止获取此ReferenceError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!