What is Strict Mode in JavaScript: Explained with 5 Real-Life Examples (And Why It Still Matters in 2025)
If you’re searching for “strict mode in JavaScript” or wondering what is strict mode in JavaScript, you’re probably either debugging code that wonβt behave or trying to become a more responsible developer (good on you β¨). Either way, youβve landed in the right place.
Table Of Content
- Key Highlights
- π What is Strict Mode in JavaScript? (Simple Definition)
- π How to Use Strict Mode in JavaScript
- β When is Strict Mode Enabled by Default?
- π Why Use Strict Mode in JavaScript? (5 Real-Life Use Cases)
- β Do You Still Need to Use Strict Mode in 2025?
- β¨ Developer Insights: How Strict Mode Helps in the Real World
- π Final Thoughts: Why Strict Mode Still Matters in JavaScript (Even in 2025)
- πββοΈ Frequently Asked Questions About use strict in JavaScript
- π Related Reads You Might Find Helpful
If you’ve been working with JavaScript for any length of time, you’ve probably seen the phrase “use strict” sitting quietly at the top of a script or function. It looks simpleβalmost forgettableβbut it carries a lot of weight.
So what exactly is strict mode in JavaScript, and why should you care?
In this article, weβll break down what strict mode does, how to use it properly. And yes, even in 2025, strict mode is still a must-know featureβespecially if you’re writing scripts outside of modern frameworks or just trying to understand how JavaScript behaves under the hood. Along the way, youβll see practical examples and understand how strict mode helps you write more secure, maintainable code.
Key Highlights
β¨ Strict mode helps catch silent JavaScript bugs that can crash your app.
π It prevents the use of undeclared variables and future-reserved keywords.
π‘ Auto-enabled in ES6 modules, but still crucial for legacy scripts.
π Learn how strict mode in JavaScript improves debugging, performance, and security.
π What is Strict Mode in JavaScript? (Simple Definition)
Strict mode in JavaScript is a way to opt into a cleaner, stricter version of the language. It was introduced in ES5 (ECMAScript 5) to help developers catch silent errors and improve code quality.
By placing ‘use strict’; at the top of a JavaScript file or inside a function, you’re telling the JavaScript engine:
βDonβt let me get away with bad habits.β
This means no more undeclared variables, no reserved keywords, no accidental globals, and better optimization opportunities for your code.

π How to Use Strict Mode in JavaScript
There are two ways to use strict mode in JavaScript:
- Enable Strict Mode Globally
Add it to the top of your file:
"use strict";
let name = "Anjali";
console.log(name);
- Enable Strict Mode in a Function
function showName() {
“use strict”;
let name = “Ravi”;
console.log(name);
}
β Important: It must be the first line in the file or function. You can place comments above it, but no actual code.
β When is Strict Mode Enabled by Default?
If youβre using any of the following, youβre already in strict mode even without writing it explicitly:
- ES6 Modules (every file with type=”module”)
- JavaScript Classes
- TypeScript (automatically enforces strict rules)
- Tools like Babel, Webpack, and frameworks like React, Vue, or Svelte
Still, if you’re writing old-school scripts or working on legacy projects, you need to enable it manually.

π Why Use Strict Mode in JavaScript? (5 Real-Life Use Cases)
Hereβs where strict mode really earns its keep.
- β Prevents Undeclared Variables
Without strict mode:
function greet() {
user = “Amit”;Β // Global variable created silently
console.log(user);
}
greet();
With strict mode:
“use strict”;
function greet() {
user = “Amit”;Β // β ReferenceError
console.log(user);
}
greet();
This helps you avoid the classic “Oops, I forgot let” bug. In real apps, accidental globals can overwrite important values, crash functions, or even expose security holes.
- β Duplicate Parameter Names
This can happen easily if you copy-paste code or work with legacy functions:
function add(a, a) {
return a + a;
}
console.log(add(2, 3)); // Output: 6 (confusing!)
But strict mode stops this nonsense:
“use strict”;
function add(a, a) {
// β SyntaxError
return a + a;
}
- β Reserved Keywords
You canβt name variables using future-reserved keywords like package, interface, static, etc.
“use strict”;
const package = “Tools”; // β SyntaxError
This prevents future updates from breaking your code unexpectedly.
- β Accessing .callee or .caller
These were once used to reference calling functions. Now, they are deprecated.
“use strict”;
function demo() {
console.log(arguments.callee); // β TypeError
}
This protects performance and avoids complex debugging in large apps.
- β Modifying Read-Only Properties
Ever tried updating an object property that shouldn’t change?
“use strict”;
const obj = {};
Object.defineProperty(obj, ‘status’, {
value: ‘locked’,
writable: false
});
obj.status = ‘open’; // β TypeError
β Do You Still Need to Use Strict Mode in 2025?
Yesβand no.
If youβre writing modern JavaScript, most of your code is already running in strict mode. But:
- Are you working with legacy code? Use it.
- Are you building browser-compatible scripts? Use it.
- Want to write better JavaScript? Always use it when in doubt.
Adding ‘use strict’; costs nothing and can prevent hours of debugging.

β¨ Developer Insights: How Strict Mode Helps in the Real World
A senior developer at Mozilla once mentioned:
βStrict mode helped us catch a subtle global assignment that was breaking our production build. It saved us hours of rollback and hotfix time.β
I personally use strict mode when writing simple browser scripts or prototyping outside React or Next.js. Itβs like wearing a seatbeltβmaybe you wonβt crash, but if you do, youβll be glad it was there.
Tip:
If you’re teaching JavaScript or mentoring junior developers, make strict mode a default habit. It teaches good practices from the start.

π Final Thoughts: Why Strict Mode Still Matters in JavaScript (Even in 2025)
Strict mode in JavaScript isnβt just an old relicβitβs a timeless best practice. It catches errors early, improves performance, and aligns with how modern engines parse your code.
Even in a TypeScript-dominated world, knowing how and why strict mode in JavaScript works helps you:
- Understand framework internals
- Debug older projects
- Write cleaner, safer code
So, the next time you write a script or function, donβt forget that tiny line:
“use strict”;
It might just save your appβand your sanity.
If you’re looking to strengthen your JavaScript fundamentals or explore TypeScript, check out JavaScript internships for beginnerβperfect for students and aspiring developers. Want to go beyond the basics? Explore Β JavaScript courseΒ and TypeScript courses designed for beginners and internship seekers.
βοΈ Want More Like This?
Explore our guides on ES6 vs ES5, JavaScript hoisting, and TypeScript strict mode to go deeper. Bookmark this blog and never miss a smarter way to code.
πββοΈ Frequently Asked Questions About use strict in JavaScript
β What is the use of ‘use strict’ in JavaScript?
The ‘use strict’ directive in JavaScript enforces a stricter parsing mode. It disables sloppy behaviors like using undeclared variables, duplicate function parameters, and reserved keywords.
If youβve ever spent hours hunting down a bug only to realize it was a missing let or typo in a variable nameβyeah, strict mode wouldβve caught that instantly.
π Itβs one of the simplest ways to write safer, cleaner, and more predictable JavaScript.
β What is the function form of ‘use strict’?
You can apply ‘use strict’ to an entire script or just a specific function. This is handy when youβre refactoring legacy code and only want to apply strict mode to a part of it.
function legacyPatch() {
“use strict”;
// Your secure logic here
}
This keeps older (non-strict) code untouched while enforcing strict rules inside that one function.
β What is ‘use strict’ in React?
Great question! In React apps (especially created with create-react-app or frameworks like Next.js), most files are ES6 modules. That means strict mode is applied automaticallyβyou donβt have to write ‘use strict’ manually.
But! React also has a separate thing called <React.StrictMode>. Donβt confuse the two.
- ‘use strict’ β JavaScript language-level rule
- <React.StrictMode> β Reactβs development tool to highlight potential problems in your app
They work differently, but both aim to help you write better code.
β Is it safe to remove strict mode?
Short answer: No.
If you’re using ‘use strict’, you’re already avoiding hidden bugs and silent errors. Removing it can reintroduce those problemsβespecially in legacy code or browser scripts.
Unless you’re 100% sure you need non-strict behavior (very rare), keep it.
β Why should I enable strict mode?
Hereβs what you get by enabling ‘use strict’:
- π No undeclared variables
- π No accidental globals
- π« No access to deprecated properties like .caller or .callee
- π Better performance (engines can optimize your code better)
- π Easier debugging
If you’re asking, “Should I use strict in JS?” β the answer is almost always yes.
β How do I disable strict mode in JavaScript?
If youβve added ‘use strict’; and want to disable it, just remove or comment out that line:
// “use strict”;
Or, isolate strict mode to just one function instead of the whole file. Thereβs no special syntax to βturn it offββyou either write the directive or you donβt.
But again, think twice before disabling it.
β Should I use ‘use strict’ in JS in 2025?
Absolutely. Even if you’re working in frameworks that enable it by default, understanding what strict mode does gives you superpowers in debugging and refactoring.
Use it when:
- Writing custom scripts
- Teaching JavaScript
- Working with non-module or browser scripts
- Refactoring legacy code
Think of it as JavaScriptβs seatbeltβsometimes annoying, but always protective.
π Related Reads You Might Find Helpful:
- π JavaScript for React Developers β A Beginnerβs Guide
- π What is Node.js? Concepts & Interview Preparation
- π Top JavaScript Projects to Boost Your Portfolio (2025)
- π What is JavaScript? β Web Designing Interview Guide
- π Download: Handling Events in JavaScript β PDF Guide

