Strict Mode in JavaScript
Strict mode ("use strict"; first line, or automatic inside modules and classes) converts silent sloppiness into errors: assignments to undeclared variables throw instead of creating globals, duplicate parameter names fail, this stays undefined (not window) in plain function calls, and octal literals plus with statements are banned.
There is no reason to write new sloppy-mode code — modules and classes opt in automatically, and explicit "use strict" covers scripts. Strict failures at development time replace global-namespace pollution and mystery-this bugs at run time.
No accidental globals
x = 5; without declaration throws ReferenceError in strict mode — sloppy mode would silently create window.x.
Honest this
Plain function calls get this === undefined instead of the global object — masking bugs become immediate crashes.
Banned relics
with statements, octal literals, duplicate params, and deleting variables all fail — the error-prone corners, fenced.
Automatic in modules/classes
ES modules and class bodies are always strict — explicit directives matter only for classic scripts.
"use strict";try { oops = 1;} catch (e) { console.log("caught:", e instanceof ReferenceError);}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in JavaScript yourself — building beats watching.