Tips for writing JavaScript code

Source: Internet
Author: User
1. Use of the plus sign "+"

Http://blog.csdn.net/semanwmj/article/details/7191940

2. Use of logical operators

 
VaR A = x & Y;

When x = true, A = y;

When x = false, A = X;

If X is false, the entire expression (X & Y) will not continue to be computed. However, if X is true, you must check whether y is true or false to determine the entire expression, | likewise.

The following is a section of kissy. JS:

 
VaR host = This, seed = (host & host [s]) || {};

Here we use & to get the if effect?

3. array push is more efficient than directly adding strings.

VaR S, html = []; html. Push ("AAAAA", "bbbbbb", "cccccccc"); s = html. Join ('');

4. Double exclamation point

 
Return !! $. Data (ELEM, name );

Is to get the meaning of the Boolean value of the variable, convert $. Data (ELEM, name) to a Boolean value, return

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.