183| });
184|
>> 185| <% if(just_registered) { %>
186| alert("Welcome!");
187| <% } %>
188|
just_registered is not defined
基本上,我想说:如果 just_registered 已定义并且为 true,则发出警报。但是,我想将所有内容设置为 false...我只想将其保留为未定义(我有大约 100 个变量)
<% if(typeof just_registered !== "undefined") { %>
基本上是检查局部变量是否存在。为此,您必须使用typeof
运算符自访问以来just_registered
这是一个未声明的局部变量,会产生引用错误。
这是最好的比较
var foo;
if (foo) { }
vs
//var foo;
if (foo) { } // ReferenceError
Where as
//var foo
if (typeof foo !== "undefined") { }
会起作用,因为使用 typeof 运算符访问未声明的变量只会返回"undefined"
而不是抛出一个ReferenceError
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)