You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
The text was updated successfully, but these errors were encountered:
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
andnode-template
break these expectations so it will not be useful information OTHER THAN for interviews.this
in the Global Scope Depends on the EnvironmentThe text was updated successfully, but these errors were encountered: