Tutorials Logic, IN info@tutorialslogic.com

Strict Mode in JavaScript use strict

Strict Mode in JavaScript use strict

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

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.

Syntax

Syntax
"use strict";

// Your JavaScript code starts here.

Why Use Strict Mode?

  • It turns accidental global variables into real errors.
  • It prevents duplicate function parameters and unsafe syntax.
  • It makes assignment failures visible instead of silently ignoring them.
  • It makes this easier to reason about in plain function calls.
  • It prepares your code for modules, classes, and modern tooling.

Enabling Strict Mode

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.

Whole Script

Whole Script
"use strict";

price = 499; // ReferenceError: price is not defined

Single Function

Single Function
function calculateTotal() {
  "use strict";

  total = 100; // ReferenceError
}

calculateTotal();

Undeclared Variables Are Not Allowed

Without strict mode, assigning to a name that was never declared can create a global variable by mistake. Strict mode blocks this immediately.

Accidental Global

Accidental Global
"use strict";

message = "Hello"; // ReferenceError

let title = "JavaScript";
const year = 2026;

Deleting Variables or Functions Is Not Allowed

The delete operator is for deleting object properties. It cannot delete declared variables or function declarations in strict mode.

delete

delete
"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.

Duplicate Parameters Are Not 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.

Parameters

Parameters
"use strict";

// SyntaxError: Duplicate parameter name not allowed
// function add(price, price) {
//   return price + price;
// }

function add(price, tax) {
  return price + tax;
}

Octal Literals Are Restricted

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.

Octal

Octal
"use strict";

// let oldOctal = 010; // SyntaxError

let modernOctal = 0o10;
console.log(modernOctal); // 8

Assignment Failures Throw Errors

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.

Read-only Properties

Read-only Properties
"use strict";

const person = { name: "Uttam" };

Object.defineProperty(person, "id", {
  value: 101,
  writable: false
});

person.id = 202; // TypeError

Getter-only Properties

Getter-only Properties
"use strict";

const circle = {
  radius: 10,
  get area() {
    return Math.PI * this.radius * this.radius;
  }
};

circle.area = 500; // TypeError

this in Strict Mode

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.

this

this
"use strict";

function showThis() {
  console.log(this);
}

showThis(); // undefined

Strict Mode and Modern JavaScript

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.

Modules

Modules
<script type="module" src="app.js"></script>

Detailed Learning Notes for Strict Mode in JavaScript use strict

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.

  • Identify the main problem this topic solves.
  • Write the smallest possible working example.
  • Change one input or option and observe the result.
  • Note the mistake that would break the example.

Strict Mode in JavaScript use strict Java review example

Strict Mode in JavaScript use strict Java review example
class StrictModeinJavaScriptusestrictReview {
    public static void main(String[] args) {
        String state = "ready";
        System.out.println("Strict Mode in JavaScript use strict: " + state);
    }
}

Strict Mode in JavaScript use strict guard example

Strict Mode in JavaScript use strict guard example
String value = null;
if (value == null) {
    System.out.println("Strict Mode in JavaScript use strict: handle the missing value before continuing");
}
Key Takeaways
  • Explain the purpose of Strict Mode in JavaScript use strict before memorizing syntax.
  • Trace the exact call expression and confirm which value reached the parentheses.
  • Test one normal case, one edge case, and one mistake case for Strict Mode in JavaScript use strict.
  • Write down why the value is not callable and what should hold the function instead.
  • Connect Strict Mode in JavaScript use strict to a real project scenario instead of treating it as an isolated definition.
Common Mistakes to Avoid
WRONG Calling a value before checking whether it actually holds a function reference.
RIGHT Trace the variable assignment, the property lookup, and the actual call expression.
Most beginner errors come from skipping the behavior behind the syntax.
WRONG Memorizing Strict Mode in JavaScript use strict without the situation where it is useful.
RIGHT Connect Strict Mode in JavaScript use strict to a concrete JavaScript task.
Purpose makes syntax easier to recall.
WRONG Testing Strict Mode in JavaScript use strict only with the perfect input.
RIGHT Include empty, missing, duplicate, incompatible, or failed cases when relevant.
Real bugs usually appear outside the perfect path.
WRONG Memorizing Strict Mode in JavaScript use strict without the situation where it is useful.
RIGHT Connect Strict Mode in JavaScript use strict to a concrete JavaScript task.
Purpose makes syntax easier to recall.

Practice Tasks

  • Modify the example so it guards with `typeof` or uses the correct method name.
  • Write one mistake related to Strict Mode in JavaScript use strict, then fix it and explain the fix.
  • Summarize when to use Strict Mode in JavaScript use strict and when another approach is better.
  • Write a small example that uses Strict Mode in JavaScript use strict in a realistic JavaScript scenario.
  • Change one important value in the Strict Mode in JavaScript use strict example and predict the result first.

Frequently Asked Questions

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.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.