Regulating scope of use strict in Javascript

‘use strict’ is gaining popularity in Javascript.

With growing support in browsers for ‘use strict’, more and more developers are employing it in their code. After all, ‘use strict’ makes life easy for a Javascript developer establishing kind of a best practices of using Javascript.

One interesting aspect of ‘use strict’ is the scope in which it casts its effect.

Generally, developers use it for global scope, mentioning it at the top of their script. This way, it regulates the entire code, generating errors wherever discrepancies are found.

But, if we don’t want ‘use strict’ to affect our entire code, then we can use it locally too. Yes, ‘use strict’ can be used within a Javascript function, as the first line of that function and this way it will affect only the code which is written inside that function.

This way, the scope of ‘use strict’ can be regulated which can prove to be useful esp. in the case of legacy applications.


Leave a Reply

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

You are commenting using your 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