Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
use strict

What is "use strict" in JavaScript?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

use strict” is an expression stating that JavaScript code should be executed in “strict mode.” The expression was introduced in ECMAScript 5.

“Strict mode” is a more restricted version of JavaScript, where semantics are altered to make the code more resilient and secure. In “strict mode,” some silent errors are changed to throw errors and disable some of the more confusing or undefined features in JavaScript.

For example, you can not use undeclared variables in strict mode :

"use strict"
a=1;

The above code throws an error while the code below executes :

a=1;
console.log(a);

Another restriction can be seen in the example below where the code throws an error as the strict mode does not allow you to delete a variable. Try removing the "use strict" statement and it will work!

"use strict"
a=1;
delete a;

Also, note that “use strict” has global scope when written at the beginning of the code while it will have a local scope if written inside a function body.

Here is an example of “use strict” in local scope:

a=1;
//this will not throw an error as "use strict" is in local scope
function strictMode() {
"use strict"
alert("I am in strict mode");
}

RELATED TAGS

javascript
use strict
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring