How do I stop getting this ReferenceError in node.js?

不打扰是莪最后的温柔 提交于 2019-12-04 15:08:52

<% if(typeof just_registered !== "undefined") { %>

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.

This is best compared to

var foo;
if (foo) { }

vs

//var foo;
if (foo) { } // ReferenceError

Where as

//var foo
if (typeof foo !== "undefined") { } 

Will work because accessing an undeclared variable with the typeof operator just returns "undefined" rather then throwing a ReferenceError

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!