简体   繁体   中英

JavaScript global variable is shown as undefined in Google Chrome console

I'm very much new to JavaScript. This question may be something very primitive. The posts that are suggested when I was typing this question didn't help me to resolve the issue.

I was following a tutorial and it uses Google Chrome console for exercises. It showed that the global and window objects tables could be printed on the console.

I tried and window was printed but not the global object. Why is this? Do I need to upgrade to a certain version of chrome/install other plugin to support global variables?

It says "Global is not defined"

在此处输入图片说明

I think I found the answer to the question.

The Chrome browser has to be in the "Incognito mode" to see the global object.

在此处输入图片说明

What do you mean by global variables? If you define a variable "var x = 0" Outside of any functions it's global and can be called anywhere.

Including in the console.

Have you perhaps run across a NodeJS tutorial where global is used to create a global variable outside of a module?

https://nodejs.org/api/globals.html#globals_global

This is not valid in browser JavaScript, even though in NodeJS it is still JavaScript, the global stuff is a little different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM