Use "use strict" directive
"use strict" is to specify that code executes under strict conditions.
You cannot use undeclared variables in strict mode.
Browser that supports strict mode: Internet Explorer 10+, Firefox 4+ Chrome 13+, Safari 5.1+, Opera 12+.
Strict mode declaration
Strict mode is declared by adding a "use strict"; expression to the head of a script or function.
In the example, we can press F12 in the browser (or click "Tools >More tools>Developer Tools ") Turn on debug mode and view error messages.
Why use strict mode:
- Eliminate some insecure aspects of code running and ensure the safety of code running;
- Improve compiler efficiency and increase running speed;