The purpose of “use strict” is to indicate that the code should be executed in “strict mode”. Strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode eliminates some JavaScript silent errors by changing them to throw errors.

For example, in strict mode, assigning a value to a non-writable property will throw an error:

“use strict”;

var obj = {};
Object.defineProperty(obj, “x”, { value: 42, writable: false });

obj.x = 9; // throws an error in strict mode

Leave a Reply

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