Sunday, 12 February 2017

What does “use strict” do in JavaScript

"use strict" is to indicate that the code should be executed in "strict mode"

Now What is "strict mode"

Strict mode makes it easier to write "secure" JavaScript.
Strict mode changes previously accepted "bad syntax" into real errors.

x = 3.14;       // This will not cause an error. myFunction();

function myFunction() {
   "use strict";
    y = 3.14;   // This will cause an error}
Try it Yourself »


"use strict" is used at global scope or in scope of function 


x = 3.14;       // This will not cause an error. myFunction();

function myFunction() {
   "use strict";
    y = 3.14;   // This will cause an error}
Try it Yourself »