Possible duplicate:
How to check if a variable is defined in JavaScript? Is there a standard function for checking null, undefined or empty variables in JavaScript?
I have a script that occurs in two parts.
The first part sets var:
var pagetype = "textpage";
The second part is a simple if statement:
if(pagetype == "textpage") { //do something };
Now the second part, the if statement, appears on all pages of my site. But the first part, where var is declared, appears only on some of my pages.
On pages without var, I get this error:
Uncaught ReferenceError: pagetype is not defined
So my question is: is there a way with JavaScript or JQ to determine if var actually exists (not only if it has data assigned to it)?
I think I would just use a different one if the statute, for example:
if ("a var called pagetypes exists")....
javascript variables jquery
MeltingDog Dec 19 '12 at 1:10 2012-12-19 01:10
source share