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




<html><head><title>Strict mode Demo</title><script>
        "use strict";

        try {
            pi = 3.14;

            alert(pi);
        } catch (e) {
            alert(e);
        }
        

    </script></head><body></body></html>


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



If Variable Are Declared In Strict Mode


<html><head><title>Strict mode Demo</title><script>
        "use strict";

        try {
          var pi = 3.14;

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


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