What is the difference between "strict" and "non-strict" modes of JavaScript?


The “use strict” is a directive, which is a literal expression. It introduced in JavaScript 1.8.5. As the name suggests, “use strict” indicates that the code is to be executed in strict mode. Under non-strict, the code won’t execute won’t execute in strict mode.

Let us declare strict mode. To declare, add the keyword “use strict” in the beginning. For global scope, declare it at the beginning of the script.

<!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>

Updated on: 16-Jan-2020

819 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements