Strict Mode in JavaScript use strict is an important JavaScript topic because it appears in real projects, debugging sessions, and interviews. Learn the meaning first, then connect it to a small working example so the rule does not stay abstract.
For this page, focus on what problem Strict Mode in JavaScript use strict solves, where developers usually make mistakes, and how to verify the result. The audit note for this lesson was: under 650 content words; limited checklist/practice/mistake/FAQ notes .
A strong understanding of Strict Mode in JavaScript use strict should include syntax, behavior, one realistic use case, one failure case, and one quick way to check your work with tools or output.
Strict Mode in JavaScript use strict should be studied as a practical JavaScript lesson, not as a label. Start by naming the input, the rule that changes the input, and the result a learner should be able to predict after reading the page.
In the javascript > strict-mode page, the notes should connect the definition with a working scenario, a mistake that beginners actually make, and the exact check that proves the fix. That makes the topic useful for coding, debugging, and interview revision.
Strict mode was introduced in ECMAScript 5. It is enabled with the "use strict" directive and tells JavaScript to reject some older, error-prone behavior instead of silently allowing it. This makes bugs easier to find, avoids accidental globals, and encourages code that works better with modern JavaScript features.
Modern JavaScript modules and class bodies are strict by default. Regular scripts and regular functions still need the directive if you want strict behavior there.
"use strict";
// Your JavaScript code starts here.
Place "use strict" at the beginning of a script or function. It must appear before other executable statements. Comments are allowed before it, but normal code is not.
"use strict";
price = 499; // ReferenceError: price is not defined
function calculateTotal() {
"use strict";
total = 100; // ReferenceError
}
calculateTotal();
Without strict mode, assigning to a name that was never declared can create a global variable by mistake. Strict mode blocks this immediately.
"use strict";
message = "Hello"; // ReferenceError
let title = "JavaScript";
const year = 2026;
The delete operator is for deleting object properties. It cannot delete declared variables or function declarations in strict mode.
"use strict";
let count = 1;
function showCount() {
return count;
}
// delete count; // SyntaxError
// delete showCount; // SyntaxError
const user = { name: "Asha" };
delete user.name; // This is allowed.
In older non-strict JavaScript, a function could accidentally use the same parameter name twice. Strict mode treats this as a syntax error because it makes code confusing.
"use strict";
// SyntaxError: Duplicate parameter name not allowed
// function add(price, price) {
// return price + price;
// }
function add(price, tax) {
return price + tax;
}
Legacy octal numbers such as 010 are confusing because they look like decimal numbers. Strict mode rejects the old format. Use the modern 0o prefix for octal values.
"use strict";
// let oldOctal = 010; // SyntaxError
let modernOctal = 0o10;
console.log(modernOctal); // 8
Strict mode throws an error when code tries to write to read-only properties, getter-only properties, or non-extensible objects. Without strict mode, these mistakes may fail silently.
"use strict";
const person = { name: "Uttam" };
Object.defineProperty(person, "id", {
value: 101,
writable: false
});
person.id = 202; // TypeError
"use strict";
const circle = {
radius: 10,
get area() {
return Math.PI * this.radius * this.radius;
}
};
circle.area = 500; // TypeError
In a normal function call, strict mode leaves this as undefined. Non-strict mode may replace it with the global object, which can hide bugs.
"use strict";
function showThis() {
console.log(this);
}
showThis(); // undefined
If you write ES modules, strict mode is already enabled automatically. This means a file loaded with <script type="module"> behaves strictly even without writing "use strict".
Because modules and classes are strict by default, most modern projects already benefit from strict rules through bundlers, frameworks, or module-based scripts.
<script type="module" src="app.js"></script>
When studying Strict Mode in JavaScript use strict, separate three things: the concept, the syntax, and the situation where it is useful. This prevents the lesson from becoming a list of commands with no practical meaning.
In JavaScript, Strict Mode in JavaScript use strict becomes easier when you build a tiny example first, then increase complexity. Add one realistic input, one invalid or boundary input, and one explanation of why the result changes.
class StrictModeinJavaScriptusestrictReview {
public static void main(String[] args) {
String state = "ready";
System.out.println("Strict Mode in JavaScript use strict: " + state);
}
}
String value = null;
if (value == null) {
System.out.println("Strict Mode in JavaScript use strict: handle the missing value before continuing");
}
Calling a value before checking whether it actually holds a function reference.
Trace the variable assignment, the property lookup, and the actual call expression.
Memorizing Strict Mode in JavaScript use strict without the situation where it is useful.
Connect Strict Mode in JavaScript use strict to a concrete JavaScript task.
Testing Strict Mode in JavaScript use strict only with the perfect input.
Include empty, missing, duplicate, incompatible, or failed cases when relevant.
Memorizing Strict Mode in JavaScript use strict without the situation where it is useful.
Connect Strict Mode in JavaScript use strict to a concrete JavaScript task.
The common mistake is memorizing syntax without understanding when the behavior changes or fails.
Remember the problem it solves in JavaScript, then attach the syntax or steps to that problem.
You can predict the result of a small example, explain a failure case, and choose it over a nearby alternative for a clear reason.
They often copy the syntax but skip the state, input, dependency, selector, route, type, or configuration that controls the behavior.
Explore 500+ free tutorials across 20+ languages and frameworks.