Why use strict mode in JavaScript ?

In this article I am going to discuss about strict mode in JavaScript.

We can use strict mode two way in a JavaScript code

  1. On the page level.
  2. On the function level.

On the page level :

Above code we used “use strict” top of the page. When we are going to run then we are getting error.Bellow is the following error.



On the function level:

Again above code we used “use strict” inside the method. When we are going to run then we are getting same error. Below is the following error.



Why we are getting above error for using “use strict”

We use this for better coding and error checking in JavaScript code. If we use strict mode then we are not allowed to do many think. Below are some following operation you cannot performing with these operation.

  • Assigning value to non-declared variable
  • Assigning value to read only variable
  • Defining duplicate property in a function
  • Cannot define a function inside else-if or for statement

There are many other operations will give error for using “use strict”. I hope you have understood the purpose of this article . Thanks for reading ||||




Leave a Reply

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