JS Small Skills Big Skill (continuous update)

Source: Internet
Author: User

1. Copy n characters
1 function (num) {2     return (new Array (++num)). Join (this); 3 }4  5var a = ' a '; 6 a.repeat (5);  // ' AAAAA '
2. Replace If...else ...
1 var result; 2 3 result = IsTrue? something:anotherthing; 4 result = Something | | anotherthing; 5 result = something && anotherthing;

3. Multi-Conditional judgment

Maybe:

1 functionYourfun (status) {2     varcolor;3     Switch(status) {4          Case0:5color = ' White ';6              Break;7          Case1:8color = ' Red ';9              Break;Ten          Case2: Onecolor = ' Yellow '; A              Break; -          Case3: -color = ' green '; the              Break; -          Case4: -color = ' Blue '; -              Break; +     } -  +     returncolor; A}

Better:

1 function Yourfun (status) {2     return [' White ', ' red ', ' yellow ', ' green ', ' Blue '][status] 3 }

. Thinking

Ensure code readability, flexible application of JS code skills. On the one hand to improve their coding ability, on the one hand to deepen the understanding of JS.

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.