Skip to content

Instantly share code, notes, and snippets.

@shreshthmohan
Created February 9, 2018 11:30
Show Gist options
  • Save shreshthmohan/ef236a44aad388d78b647e13e60f2b28 to your computer and use it in GitHub Desktop.
Save shreshthmohan/ef236a44aad388d78b647e13e60f2b28 to your computer and use it in GitHub Desktop.
Global - Execution Context, Object // source http://jsbin.com/casasuc
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Global - Execution Context, Object</title>
</head>
<body>
<p><a><b>this</b> behaves diffrently in the browser vs Node.js</a></p>
<script id="jsbin-javascript">
console.log(this);
console.log(this === window);
console.log('The base/global execution constant creates two things, a global object (objects are simply name value pairs, remember?) and *this*. this is also equal to the global object. Inside the broswer window is the global object.')
if (this === window) {
console.log('this is same a window object');
}
console.log('There would be a different window/global object in another browser window. Each tab is a different execution context and so it would have it\'s own global/window object.');
</script>
<script id="jsbin-source-javascript" type="text/javascript">console.log(this);
console.log(this === window);
console.log('The base/global execution constant creates two things, a global object (objects are simply name value pairs, remember?) and *this*. this is also equal to the global object. Inside the broswer window is the global object.')
if (this === window) {
console.log('this is same a window object');
}
console.log('There would be a different window/global object in another browser window. Each tab is a different execution context and so it would have it\'s own global/window object.');
</script></body>
</html>
console.log(this);
console.log(this === window);
console.log('The base/global execution constant creates two things, a global object (objects are simply name value pairs, remember?) and *this*. this is also equal to the global object. Inside the broswer window is the global object.')
if (this === window) {
console.log('this is same a window object');
}
console.log('There would be a different window/global object in another browser window. Each tab is a different execution context and so it would have it\'s own global/window object.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment