Anderson
Anderson

Reputation: 143

What is the global scope in javascript? How can I create one?

When running code on Chrome Inspector's console and typing the this keyword, I can see the global scope object that is exposed with many properties already set. But, how can I create mine? Or when I call a function, the call-site is the "global scope" of that function?

I'm reading YDKJS book series and some concepts get really confusing sometimes.

Upvotes: 0

Views: 34

Answers (1)

gkelly
gkelly

Reputation: 288

First of all Kyle Simpson's series You Don't Know JavaScript is very nice. Few know that topic as well as he does.

Second, in the context of a browser, what you are calling global variables are all variables that are owned by the Window object. So, keep that in mind when naming them so you don't clobber an existing and important property.

Third, learn more JavaScript and realize you can generally avoid using these types of variables

Upvotes: 1

Related Questions