Topic: My global variable - why is it undefined? |
|
---|---|
Author | Thread |
Nervous Wreck (II) Inmate From: |
posted 08-28-2009 18:11
I code my global variables first, code: var globvar = { oneTimeSwitch: "0", kbinput: document.createElement("INPUT"), kbdivision: document.createElement("DIV"), etc. } window.onload = function() { if (kbinput==undefined) alert("NO KBINPUT"); setTriggers(); }
|
Paranoid (IV) Inmate From: Norway |
posted 08-29-2009 10:22 |
Nervous Wreck (II) Inmate From: United States |
posted 08-29-2009 22:50
As poi said, kbinput is undefined because you never defined it. The reason you received the error rather than seeing "NO KBINPUT", however, is because you can't check for undefined global variables using the == operator unless you check them in terms of the window object. E.x. kbinput==undefined throws an error, but window.kbinput==undefined would show your error message. Object properties need not be prepended with "window.", however -- globvar.kbinput==undefined would work just fine. |
Nervous Wreck (II) Inmate From: |
posted 05-31-2011 11:07
Edit TP: spam removed
|