F
Fabian
How can I check whether or not a variable exists in a script? I'm
thinking in terms of
if (my variable exists) { myfunction(); }
thinking in terms of
if (my variable exists) { myfunction(); }
Fabian said:How can I check whether or not a variable exists in a script? I'm
thinking in terms of
if (my variable exists) { myfunction(); }
thinking in terms of
if (my variable exists) { myfunction(); }
if(typeof x != 'undefined'){
...
}
Is as near as you can get. But a variable that is declared but has not
yet been assigned a value will also return 'undefined' from a typeof
test. A declared variable could be said to "exist" but in reality this
is probably suitable to your problem.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.