CompileProgramThe key is that the program is written to people, not to computers. If you can understand that others may read your JavaScript, you will write more clearly.Code. The clearer the code, the more difficult it is to make mistakes. Clever code is cute, but this clever code will produce errors. The best rule of thumb is kiss, that is, keep it simple and Sweetie (keep simple and cute ). Another helpful technique is to make comments before writing code. This forces you to think about it first. Once a comment is written, you can write the code below it.
The following is an example of writing a function using this method:
Step 1: write comments
Step 2: Fill in the code
This method not only forces you to think before writing code, but also makes the coding process look easier-by dividing tasks into small, easy-to-code parts, your problem does not look like Mount Everest, but like a group of pleasant ups and downs.
Last... End each statement with a semicolon.
Although it is not strictly required, you should develop the habit of ending each statement with a semicolon, which can avoid further code in this line. If you forget the extra points, the next line of good code will suddenly generate an error. Initialize the variable as "Var" unless you have a better reason not to do so. Using "Var" to localize variables can reduce the chance of confusion between one function and another unrelated function.
Now that you know how to code, let's learn how to make
Your JavaScript code runs quickly.>
---------------------------------------------------------
Speed-based JavaScript code optimization
1. Restrict the workload in the cycle
2. Customize the if-then-else statement in the most likely to impossible order
3. Expression for minimizing repeated executions
refer to URL: http://blog.csdn.net/java2000_net/archive/2008/10/10/3046871.aspx