JavaScript Strict mode

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

Strict mode opts into a safer subset of JavaScript: assigning undeclared variables throws, this is undefined in bare calls, and some footguns are disabled. ES modules and modern class bodies are strict by default.

JavaScript Syntax

JavaScript
"use strict";
try {
  undeclared = 1;
} catch (err) {
  console.log(err.name);
}
Try it Editor

How It Works

  1. No auto-global. Undeclared assignment throws.
  2. Catch reports. ReferenceError.

Examples

Example 1 — this in functions

Bare calls get undefined this.

JavaScript
"use strict";
function f(){ return this; }
console.log(f());
Try it Editor

How It Works

  1. Not the global object in strict mode.

Example 2 — Duplicate params

Illegal in strict mode.

JavaScript
console.log("function (a,a){} is SyntaxError in strict");
Try it Editor

How It Works

  1. Helps catch typos.

Example 3 — Modules are strict

No pragma needed.

JavaScript
console.log("type=module enables strict automatically");
Try it Editor

How It Works

  1. ES modules always strict.

Frequently Asked Questions

Yes. Prefer modules or put "use strict"; at the top of scripts.
No. It changes error checking and this binding rules.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful