---
title: "What is strict mode and how do you enable it?"  
description: "What is strict mode and how do you enable it?"  
author: "Ravi Vishwakarma"  
published: 2025-12-30  
updated: 2026-03-29  
canonical: https://answers.mindstick.com/qa/116248/what-is-strict-mode-and-how-do-you-enable-it  
category: "programming"  
tags: ["angular"]  
reading_time: 2 minutes  

---

# What is strict mode and how do you enable it?

**What is [strict mode](https://www.mindstick.com/forum/160061/what-is-javascript-strict-mode-and-why-is-it-used) and how do you enable it?**

`ng new my-app --strict`

## Answers

### Answer by Anubhav Sharma

> **[Strict](https://www.mindstick.com/blog/12367/various-means-of-commuting-for-students-on-a-strict-budget) [Mode](https://answers.mindstick.com/qa/50412/how-to-fix-an-iphone-x-that-is-stuck-on-recovery-mode)** is a feature in **JavaScript** that helps you write cleaner, safer, and more secure code by enforcing stricter parsing and error handling rules.

## What is Strict Mode?

Strict mode eliminates some silent errors and makes them **visible (throws errors)**. It also prevents the use of unsafe or outdated JavaScript features.

### Key Benefits:

- Catches common coding mistakes
- Prevents use of undeclared variables
- Disallows duplicate parameter names
- Makes debugging easier
- Improves performance in some cases

## How to Enable Strict Mode

You enable strict mode using a simple directive:

### 1. For Entire Script

```javascript
"use strict";

x = 10; // Error: x is not defined
```

### 2. Inside a Function

```javascript
function myFunction() {
    "use strict";
    y = 20; // Error
}
```

## Example Without Strict Mode

```javascript
x = 10; // No error (bad practice)
console.log(x);
```

## Example With Strict Mode

```javascript
"use strict";

x = 10; // ReferenceError
```

## Important Rules in Strict Mode

- **No undeclared variables**

```plaintext
"use strict";
a = 5; // Error
```

- **No duplicate parameters**

```plaintext
function sum(a, a) { } // Error
```

- **No deleting variables**

```plaintext
delete x; // Error
```

- `this` **behaves differently**

   - In strict mode, `this` is `undefined` in functions (not global object)

## When Should You Use It?

- Always use strict mode in modern JavaScript development
- Especially important for large-scale applications and production code

## Pro Tip

If you're using modern JavaScript (ES6 modules), strict mode is **automatically enabled**.


---

Original Source: https://answers.mindstick.com/qa/116248/what-is-strict-mode-and-how-do-you-enable-it

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
