JavaScript Interview Question #99

What is strict mode in JavaScript?

Promises, Async/Await, Fetch & Modern JavaScript Mid-Level Intermediate

Quick Interview Answer

Strict mode enables a stricter set of JavaScript runtime rules that convert some silent mistakes into errors and change certain legacy behaviors. It can be enabled for classic scripts or individual functions with "use strict".

Detailed Explanation

Strict mode enables a stricter set of JavaScript runtime rules that convert some silent mistakes into errors and change certain legacy behaviors. It can be enabled for classic scripts or individual functions with "use strict".

ES modules and class bodies use strict-mode semantics automatically. Modern applications using modules therefore often do not need to add the directive manually.

Code Example

"use strict";

function update() {
    // accidentalGlobal = 10;
    // ReferenceError instead of creating a global variable
}

update();