Skip to content

Instantly share code, notes, and snippets.

@skrajewski
Created May 31, 2021 07:04
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 skrajewski/3c6690519a8b13bfdc3ac5ae203cacdb to your computer and use it in GitHub Desktop.
Save skrajewski/3c6690519a8b13bfdc3ac5ae203cacdb to your computer and use it in GitHub Desktop.
Global object difference between Browser and Node

Output in Browser:

undefined
undefined
{test: "abcd"}
"abcd"

Output in Node:

undefined
undefined
prepareTest { test: 'abcd' }
undefined
function prepareTest() {
this.test = "abcd";
}
// global
console.log(this.test);
const a = prepareTest();
const b = new prepareTest()
console.log(a);
console.log(b);
// global
console.log(this.test);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment