What does "use strict" do in JavaScript, and what is the reasoning behind it?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
"use strict" enables JavaScript strict mode, which turns off some historically permissive language behavior and makes certain mistakes fail fast instead of silently succeeding. The reasoning behind it is simple: early JavaScript allowed too many ambiguous or error-prone patterns, and strict mode was introduced to make code safer, more predictable, and easier for engines to optimize.
What strict mode changes
Strict mode does not create a new language. It changes the rules for some existing behaviors.
One major example is accidental globals. In sloppy mode, assigning to an undeclared variable creates a global in many environments. In strict mode, it throws.
That is one of the biggest practical benefits because accidental globals are a classic source of hard-to-debug bugs.
this becomes safer in plain function calls
In non-strict mode, calling a plain function can bind this to the global object. In strict mode, this stays undefined unless explicitly bound.
This prevents a lot of accidental global-object mutation.
Silent failures become visible
Strict mode turns some silent errors into thrown exceptions. That is good because silent failure usually hides a bug rather than helping the program recover.
Examples include:
- writing to some non-writable values
- deleting certain protected names
- invalid assignments that old JavaScript tolerated badly
The language becomes less forgiving in exactly the places where forgiveness created confusion.
Duplicate parameter names and other restricted syntax
Strict mode rejects some confusing syntax that older JavaScript allowed.
That is a syntax error in strict mode. The point is not to be annoying. The point is to stop code patterns that are unclear and easy to misuse.
eval and scope behavior become more predictable
Historically, eval was one of the messier corners of JavaScript. Strict mode limits some of its surprising scope effects, which makes surrounding code easier to reason about.
In practice, this is less about writing eval yourself and more about making the language semantics cleaner and more optimizable.
Why strict mode was introduced
Early JavaScript prioritized flexibility and loose behavior. That made it easy to get started, but it also made it easy to write code that accidentally relied on mistakes.
Strict mode was introduced in ECMAScript 5 as an opt-in cleanup layer. The goals were:
- catch common bugs earlier
- reduce dangerous or confusing language behavior
- make the language easier to optimize internally
- prepare JavaScript for more modern features and patterns
So the reasoning is not only “more errors.” It is “better semantics for large, maintainable programs.”
Why modern code often does not need to write it manually
A very important modern detail is that ES modules and JavaScript classes already run in strict mode automatically.
That means in code like this:
strict mode is already in effect because modules are strict by default.
So the explicit directive matters most in classic script files or older codebases. In module-based applications, you often get strict mode without adding the string yourself.
When to use it today
If you are writing old-style script files that are not modules, "use strict" is still a good idea.
If you are writing modern module-based JavaScript, you usually do not need to add it manually because the runtime already gives you strict semantics.
So today the practical value of understanding strict mode is more about knowing the semantics than about typing the directive everywhere.
Common Pitfalls
A common mistake is assuming "use strict" is still required inside ES modules. It is not.
Another mistake is thinking strict mode only affects syntax. It also changes runtime behavior such as this binding and accidental global creation.
A third mistake is blaming strict mode for “breaking old code” when the real issue is that the old code depended on unsafe behavior.
Summary
- '
"use strict"enables stricter JavaScript semantics.' - It turns some silent mistakes into errors and blocks unsafe patterns.
- It helps prevent accidental globals and makes
thisbehavior safer. - It was introduced to make JavaScript more predictable and maintainable.
- ES modules and classes already run in strict mode automatically.

