Javascript – How to determine if a JavaScript variable is defined in a page?

javascript

How can i check in JavaScript if a variable is defined in a page? Suppose I want to check if a variable named "x" is defined in a page, if I do if(x != null), it gives me an error.

Best Solution

I got it to work using if (typeof(x) != "undefined")