Strict Mode & this keyword in JavaScript
Normally, in global scope this keyword refers to Window object. Eg:
<script>
console.log(this); //returns Window object.
//or
(function(){)
console.log(this); //returns Window object
})();
</script>
HOWEVER, in JavaScript strict mode, this keyword in global scope is undefined. Eg:
<script>
(function(){
"use strict";
console.log(this); //will return *undefined*
})();
</script>
So use the strict mode wisely. Here you can read more fun things about JavaScript Strict Mode: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode
Written by Shekhar Sharma
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#