Skip to content

Instantly share code, notes, and snippets.

@shreshthmohan
Created February 9, 2018 11:32
Show Gist options
  • Save shreshthmohan/343767e6b929df282bb0ae97a9a02451 to your computer and use it in GitHub Desktop.
Save shreshthmohan/343767e6b929df282bb0ae97a9a02451 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>Look in the console.</p>
<p><a href="https://stackoverflow.com/questions/34838659/the-this-keyword-behaves-differently-in-nodejs-and-browser" target="_blank"><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