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



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

183| }); 184| >> 185| <% if(just_registered) { %> 186| alert("welcome!"); 187| <% } %> 188| just_registered not defined

basically, want say: if just_registered defined , true, alert. however, want want set false...i want leave undefined (i have 100 variables)

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

basically checking whether local variable exists. have utilize typeof operator since accessing just_registered undeclared local variable creates reference error.

this best compared

var foo; if (foo) { }

vs

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

where as

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

will work because accessing undeclared variable typeof operator returns "undefined" rather throwing referenceerror

javascript templates node.js ejs

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -