What does “use strict” do in JavaScript, and what is the reasoning behind it?

The directive “use strict” refers to a literal expression. JavaScript 1.8.5 introduced it. It is named “use strict” because it indicates that the code was executed in strict mode.

Let us declare strict mode. Add the keyword “use strict”, at the beginning, to declare strict mode. Declare it at the start of the script for global scope.

Example

<!DOCTYPE html>
<html>
   <body>
      <p>An error would come, since you have used a variable, but forgot to declare it</p>
      <p>Press F8 to see the error.</p>
      <script>
          "use strict";
          a = 1;
       </script>
    </body>
</html>

 

 

 

Exit mobile version