What is JavaScript's strict mode?

Answer

Strict mode (ES5) is an opt-in mode that makes JavaScript more restrictive, catching common errors and preventing unsafe features. Enable for a file: "use strict"; at the top. Enable for a function: function fn() { "use strict"; }. ES6 modules and classes are automatically in strict mode. Changes in strict mode: undeclared variables throw ReferenceError (instead of creating globals), this in regular functions is undefined (instead of global), duplicate parameter names throw SyntaxError, writing to read-only properties throws TypeError (instead of silently failing), deleting non-configurable properties throws TypeError, with statement is forbidden (ambiguous scoping), eval does not introduce variables into surrounding scope, and arguments.caller/callee are disallowed. Strict mode makes refactoring safer and enables better engine optimizations. Always use it in new code — or better yet, use ES modules which are automatically strict.