this keyword and strict mode in JavaScript

this is an referencing alias.

Automatically define in the scope of a function along with arguments.

In global execution context mode i.e. outside a function this will always refer to the global objects.


Strict Mode: Keyword Introduced in ES5.

In strict mode we can not use undeclared function.

“use strict”;

var v = “Hi!  I’m a strict mode script!”;

x = 15; ‘//  This will give a error that x is not defined.

strict mode makes it easier to write secure JavaScript.

In Function context value of this is depend on how function is called.

If we are in Strict Mode default to this keyword is undefined.

If in non strict mode then default to this keyword is global objects.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s