Skip to content

Instantly share code, notes, and snippets.

@fhsinchy
Created May 27, 2020 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhsinchy/e015a86051c81adbefa62b3cb9550786 to your computer and use it in GitHub Desktop.
Save fhsinchy/e015a86051c81adbefa62b3cb9550786 to your computer and use it in GitHub Desktop.
let globalThis = this;
function func1() {
let num = 5;
console.log(`num: ${num}`);
console.log('Global This: ', globalThis);
console.log('Local This: ', this);
console.log('Are they same?', globalThis === this);
}
function func2() {
let num = 10;
console.log(`num: ${num}`);
console.log('Global This: ', globalThis);
console.log('Local This: ', this);
console.log('Are they same?', globalThis === this);
}
func1();
func2();
// num: 5
// Global This: Window
// Local This: Window
// Are they same? true
// num: 10
// Global This: Window
// Local This: Window
// Are they same? true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment