1th: Understand the JS version you use
Many JS engines support the const keyword definition variable, but the ECMAScript standard does not define any semantics and behavior about the const keyword. Also, the behavior of the Const keyword is different between implementations.
In some cases, the const keyword-decorated variable cannot be updated:
1 Const PI = 3.14.592653589793; 2 PI = "Modified"; 3 // 3.14.592653589793
View Code
The other implementation simply treats the const as a synonym for Var:
Const PI = 3.14.592653589793; PI = "Modified"; PI; "Modified"
ES5 introduces another version control consideration-the strict mode (strict modes). This feature allows you to choose to disable the use of some of the more problematic or error-prone features in the JS language in the restricted JS version. Because of their backward-compatible syntax design , strict code can still be executed even in environments where strict pattern checking is not implemented.
The way to enable strict mode in a program is to add a specific string literal "use strict" at the very beginning of the program , and you can also add this directive to enable strict mode of the function at the beginning of the function body.
function f (x) {"Use strict";//... }
If you do not test under ES5, writing code runs in a ES5 environment and is prone to error.
function f (x) { "use strict"; var argments = []; Error:redefinition of Argments }
In strict mode, the argments variable is not allowed to be redefined. However, an environment that does not implement strict pattern checking will accept this code, so it will cause the program to fail in a product environment that implements ES5.
Writing high-quality JavaScript code (1-10)