Hey guys I am back with another blog post. In this post we will be discussing What does “use strict” do in Javascript, and what is the reasoning behind it?Let’s start by seeing What is this “use strict” keyword in Javascript.

DEFINATION

Strict Mode or “use strict” is a new feature introduced in ECMAScript 5 that allows you to place a program, function or variable in a strict operating context or environment. This strict context or environment restricts more actions from being taken accidentally by developers and it issues various exceptions which are thrown when certain conditions are not fulfilled.

FEATURES

  • It helps in catching various coding wrong practices and errors by throwing some kinds of exceptions.
  • It prevents access to the global object by throwing errors so that no unwanted access is gained by stranger.
  • You can apply strict mode to a single section of code i.e. function or you can apply it to the whole file.

HOW TO USE IT?

In order to use it in your program just type the keyword “use strict” at the top and then write your code at the bottom. All the code below the keyword will be interpreted according to the rules and it will be strict.

WHEN TO USE IT?

So the question arises when to use it. You should use this feature smartly in those situations when the need arises. You can use this in brand new Javascript applications where you think that you will bound to make mistakes in the future so just declare this keyword at the top of the script and by this you will make less errors and your code will be easy to debug and maintain. But you should definitely avoid using it in those situations where you have an existing application and then you are inserting this keyword. This can break your application as your code is not compatible with the rules of this keyword.

This is the end of the post and you have successfully understood What is “use strict” in Javascript and when to use it Thank you very much for reading this post and also please subscribe to our newsletter for receiving more posts like this.

A programmer scientist by the mind and a passionate blogger by heart ❤️. Fountainhead of Coding Shiksha Life motto: Live while you can! Teach & inspire while you could & Smile while you have the teeth.

Gautam Sharma

Founder , Coding Shiksha

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *