Skip to solution
mediumFrontend

What does 'use strict' do?

228 views
01

Understand the problem

Question presented to candidate: "What does adding 'use strict' at the top of a file actually change about how the code runs? Give me two or three concrete behavior differences, not just 'it makes errors stricter.'"

What a strong answer should cover:

  • 📌 Interview term: 'use strict' — a directive (a special string literal, not a comment) that opts a script or function into a stricter variant of JavaScript's semantics, turning several silent failures/quirky behaviors into real, thrown errors.
  • 📌 Interview term: undeclared-variable throw — verified directly: in sloppy mode, assigning to a variable that was never declared silently creates a global variable; in strict mode, the identical assignment throws a real ReferenceError.
  • 📌 Interview term: this in a plain function call — verified directly: calling a plain (non-method) function in sloppy mode gives this the global-ish object; in strict mode, this is genuinely undefined — a real, observable difference that prevents accidentally mutating global state through a mis-bound this.
  • 📌 Interview term: silent-failure-to-throw conversion — verified directly: assigning to a property of a frozen object silently no-ops in sloppy mode (no error, and the value just doesn't change); in strict mode, the identical assignment genuinely throws a real TypeError.
  • A precise answer names that classes and ES modules are implicitly strict — no directive needed, verified directly — while plain <script> tags and CommonJS modules are sloppy by default unless the directive is explicitly added.

Clarifying questions expected:

  • None — this is a definitional/technical question; naming 2-3 concrete, verified behavior differences (not a vague "it's safer") is the strong signal.

Code / implementation expected: Yes — demonstrating at least one sloppy-vs-strict contrast directly (undeclared globals or the frozen-object throw) proves real, not memorized, understanding.

strict-mode
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals interviews. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every sloppy-vs-strict contrast below was actually run in Node — not recited from documen

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal sloppy-vs-strict-mode behavior differences: undeclared globals, this, and frozen objects
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 107 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track