The syntax of Javascript is loosely, and everyone's impression of the language may be " simple ", which I think is the opposite. Using strict mode prevents you from writing poorly written syntax code. While strict mode is applied, some of the errors reported by the console require a lot of effort to eliminate, but in the long run, it helps you write clean, scalable code.
We need to insert the "use strict" directive in the definition of the function , so that the parser will execute the script with stricter rules. This directive should be a programming principle for JavaScript.
1 function salad () {23 "use strict"; 4 5 // There 's a need to write more rigorous statements here. 6 }
In the face of JavaScript loose grammar, I still prefer strict grammar. I've been encouraging myself to use strictbecause it helps me write robust, highly adaptable, portable code.
We know the mechanism used by the browser rendering engine to load JavaScript source files, which is implemented in such a way that other resources will be blocked when parsing JavaScript code. In view of this, we need to reduce the size of JavaScript files in addition to improving performance internally .
Yui Compressor(www.refresh-sf.com/yui/) is a component of the Yui framework developed and maintained by Yahoo , which removes all the spaces in the code to improve execution efficiency. To improve the speed of its operation. You can upload the source code to him, but note that the compressed code is basically not maintainable, which is why I recommend the use of "strict" reason, at the same time, the best way is to leave a copy of the uncompressed source files, for maintenance use.
There is also an online service website called JSLint (http://www.jslint.com), which parses the code and finds out the syntax errors and formatting problems, the check mechanism is very strict and helps you create a more refined and robust program.
"Use strict" strict mode and code compression