Why javascript throws Uncaught ReferenceError
when trying to get global variable directly for example someVar
, but when trying get it through window.someVar
it gots undefined
Asked
Active
Viewed 77 times
-3

Narek Mamikonyan
- 4,601
- 2
- 24
- 30
-
`Uncaught ReferenceError` is raised when you try to access nonexistent variable. When you try to reach for nonexistent **property** you get undefined because it was not defined upon the object. This information is googleable and explained well on MDN. I suggest you research such questions before you ask here, you'll get results quicker and possibly no downvotes.. – Mjh Oct 02 '15 at 11:38
1 Answers
0
Please post an example of your code. Global variables should be accessible on the window object for example:
var someValue = "foo";
function alertsomeValue(){
alert(window.someValue);
}
alertsomeValue();
//alerts "foo"

Tom Cox
- 41
- 1
- 4