JavaScript variable undefined vs not defined
I have an HTML page with the following JavaScript attached. alert(box); box = "Thinking outside the box"; In the console I get "Uncaught ReferenceError: box is not defined" when I change it to: alert(box); var box = "Thinking outside the box"; The alert gets called and shows undefined. I need to be able to explain this, I have a vague idea of why this happens. I know that when I use var, JavaScript knows the variable is there before the alert is executed, but has not necessarily assigned a value to it?? Am I way off here? Need some help understanding this. jfriend00 When you define a variable