JavaScript – Use Strict

Leave a comment

“use strict” is a feature of JavaScript that tells the compiler to use a strict context. For example, consider the code below. This code produces no errors, and displays “1” in the console:

    "use strict";
    try
    {
        var i = 1;
        console.log(i);
    }
    catch(e)
    {
        console.error(e);
    }

However, let’s say we didn’t include “var” before our variable. In normal JavaScript without using “use strict”, this would be fine. However, with “use strict”, it throws an error:

    "use strict";
    try
    {
        var i = 1;
        console.log(i);
    }
    catch(e)
    {
        console.error(e);
    }

For more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, BI, Web, Cloud and Data Science.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

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