Skip to content

Instantly share code, notes, and snippets.

@kerryChen95
Created March 18, 2013 18:33
Show Gist options
  • Save kerryChen95/5189579 to your computer and use it in GitHub Desktop.
Save kerryChen95/5189579 to your computer and use it in GitHub Desktop.
`this` in global and local execution context
var foo = 'foo';
console.log(this.foo); // 'foo'

In global execution context, declaring a variable means add a property to this

(function () {
  var bar = 'bar';
  console.log(this.bar); // undefined
})();

But not in local execution context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment