Read the "JavaScript language essence" note

Source: Internet
Author: User

First, some write code considerations

Use of 1.parseInt

Because in octal, 8 and 9 are not numbers, so

Generates 0 as a result, which causes the program parsing time and date to appear incorrectly. Therefore, it is recommended to use parseint to pass 10.

The result of parseint ("08", 10) is 8

2. When using the for in loop, it is best to add

 for inch obj) {  if  (Obj.hasownproperty (MyVar)) {

}

}
To rule out the properties from the prototype chain.

3. How to determine whether a value is a number
var isnumber = function Isnumber (value) {  return typeof value = = = ' Number ' && isfinite (value);} 


4. Use
  
If (ok) {  t = true;  } 

Replace

if (OK) T = true;

5. Use

var foo = function foo () {};

Replace

  

function foo () {};

6. In addition to the for function if switch try while, All statements are followed by a semicolon.

7. Do not exceed 100 words per line of code, beyond the line to be wrapped. Line breaks after punctuation and operators.

8. Use + = 1-=1 instead of + +--

 

Read the "JavaScript language essence" note

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.