I’m trying to do this:
var currentpage = page ? page : null;
However, if page is not yet defined, the script throws an error. Even if I test page for being undefined, as soon as the script looks up page it errors.
Why and what’s the way around this issue?
Update : Made the code-example clearer;
Trying to read from an undeclared variable simply throws a
ReferenceErrorand terminates the script.The better question is, why you don’t know whether your variable exists. Under normal circumstances, this usually implies you’re doing something bad. Why is it that you need to check for that situation? Surely, there is a better way that we could suggest.