Last Updated: September 09, 2019
·
5.653K
· shekhardesigner

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