JavaScript Basic

What is strict mode (use strict)? What are its benefits?

AI Practice

Strict Mode ('use strict')

How to Enable

Add at the top of a file or function:

'use strict';

// Or inside a function
function foo() {
  'use strict';
}

ES6 class and module are strict by default.


Benefits of Strict Mode

1. Prevents implicit global variables

'use strict';
x = 10; // ReferenceError: x is not defined

2. this is undefined in functions (not global)

'use strict';
function foo() { return this; }
foo(); // undefined (non-strict: window)

3. Prevents deleting non-deletable properties

'use strict';
delete Object.prototype; // TypeError

4. Disallows duplicate parameter names

'use strict';
function foo(a, a) {} // SyntaxError

5. Reserves future keywords

'use strict';
let eval = 1;      // SyntaxError
let arguments = 2; // SyntaxError

Summary

Strict mode makes JavaScript safer and easier to debug — it's considered best practice in modern development.

✦ AI Mock Interview

Type your answer and get instant AI feedback

Sign in to use AI scoring

Copyright © 2026 Wood All Rights Reserved · FE Interview Hub