Articles → JavaScript → Strict Mode In Javascript

Strict Mode In Javascript






What Is Strict Mode?





Syntax


“use strict”



If Undeclared Variable Is Used In Strict Mode




<script>
    "use strict";
    try {
        pi = 3.14;

        alert(pi);
    } catch (e) {
        alert(e);
    }        
</script>

Try It

Picture showing the exception message when variable is not declared in strict mode



If Variable Are Declared In Strict Mode


<script>
    "use strict";
    try {
      var pi = 3.14;

        alert(pi);
    } catch (e) {
        alert(e);
    }
</script>

Try It

Picture showing the output of the strict mode



Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, June 2, 2020

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250