Turn strict mode on/off explicitly (in ES5)
WHEN (global) code starts with "use strict" THEN strict mode is turned on for the whole file/module
WHEN eval code starts with "use strict" THEN the executed code is run in strict mode
WHEN a function starts with "use strict" THEN the code inside of it is run in strict mode
WHEN the code passed to new Function()
starts with "use strict" THEN the code is run in strict mode
Links
The MDN docs about strict mode.
Chapter 4.2.2 in the specification explains that and why ECMAScript offers a "strict mode" to restrict language features, and that it can coexist with non-strict code in the same program.
Chapter 10.1.1 in the specification explains how to turn strict mode on and off.
Appendix C "The strict mode restriction and exceptions" explains the differences between strict mode and non-strict mode in detail.
Required Knowledge
- `new Function()` and `Function()` (Function constructor)
Related Katas
Strict mode
- Turn strict mode on/off
Difficulty Level
ADVANCED
First Published
16 October 2023
Stats
4 tests to solve