Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Global object and scope section #50

Open
MicFin opened this issue Feb 27, 2017 · 0 comments
Open

Simplify Global object and scope section #50

MicFin opened this issue Feb 27, 2017 · 0 comments

Comments

@MicFin
Copy link
Contributor

MicFin commented Feb 27, 2017

The following should be removed as discussed with @jrhorn424 because it is out of scope of the lesson and adds confusion. Also, our browser-template and node-template break these expectations so it will not be useful information OTHER THAN for interviews.

this in the Global Scope Depends on the Environment

In browsers
The top-level scope is the global scope.
In the top-level scope in browsers `this` is equivalent to window.
- That means that in browsers if you're in the global scope let/const/var will define a global variable.

In Node.js
The top-level scope is not the global scope.
-In the top-level code in a Node module, `this` is equivalent to `module.exports`.
-That means if you let/const/var inside a Node.js module will be local to that module.
Node does have a global variable named global and is documented [here](https://nodejs.org/api/globals.html#globals_global).
-Since let/const/var variables are local to each module,
-global is the true global variable that is shared across modules.

-console.log("In Browser vs In Node: this is ", this);
-console.log("this === window, ", this === window);
-console.log("this === module.exports, ", this === module.exports);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant