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

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -