Home > database >  JS - Why can't the Chrome console access my global variable?
JS - Why can't the Chrome console access my global variable?

Time:04-08

I have the following variable declared at the top level of the script:

var region = southwest;

When running

console.log(region)

I'm getting the following error:

VM1094:1 Uncaught ReferenceError: region is not defined at :1:13

Not sure what is causing this given the variable is global.

CodePudding user response:

Is "southwest" a string or a variable that you have assigned to the 'region' variable? If it's a string, you need to put it inside the "double quotes". And, if it is a variable, then you need to assign some value to it.

CodePudding user response:

when you have global variables they will be assigned to window object , in your console try console.log(window.region)

  • Related