InterviewHubPRO
Section Overview
Q71

Question 71 of 521

Part 2: Promises, Callbacks, Async & Strict Mode (54 - 103)

14%
JavaScript Internals (521 Qs)•Part 2: Promises, Callbacks, Async & Strict Mode (54 - 103)

What is a strict mode in javascript

JavaScript’s "use strict" directive is used to opt into a stricter parsing and error-handling mode for your scripts or functions. It helps catch common bugs, makes your code more secure, and prepares it for future versions of JavaScript.

Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. This way it prevents certain actions from being taken and throws more exceptions. The literal expression "use strict"; instructs the browser to use the javascript code in the Strict mode. This also enables block-scoped variables.

Practical Code Example

javascript
'use strict';

// 1. Prevents accidental global variable creation
// typoVariable = 42; // ReferenceError: typoVariable is not defined

// 2. Disallows deleting undeletable properties
// delete Object.prototype; // TypeError: Cannot delete property

// 3. Prevents duplicate parameter names
// function sum(a, a, c) {} // SyntaxError: Duplicate parameter name