JavaScript Learning Note 1

Source: Internet
Author: User

One, use of the switch branch statement:

Common methods for 1,switch statements:

   
1Let number = 25;2 3 Switch(number) {4      CaseNumber < 10:5Alert (10);6          Break;7      CaseNumber > 20:8Alert (20);9          Break;Ten     default: OneAlert (' No '); A          Break; -}

The 2,switch statement can also be used to determine the range by setting a Boolean value:

  

1Let number = 25;2 3     Switch(true){4          CaseNumber < 10:5Alert (10);6              Break;7          CaseNumber > 20:8Alert (20);9              Break;Ten         default: OneAlert (' No '); A              Break; -}

  Summary: In the use of the switch statement, by setting a Boolean value compared to the value of the case, can be freed from the judgment of the IF statement, the immediate scope of the judgment can also be in the branch statement to clear expression.

two, understanding function parameters
    function Sayhi () {        console.log (' Hello, ' + arguments[0], arguments[1]);    }    Sayhi (' Hang San ', ' SB ');  Hangsan  SB

In the above function, when we call the Sayhi () function, the arguments passed by the function are passed in the arguments array, and when we define the anonymous function, we can even directly do not define the anonymous parameters, but directly on the arguments. Of course, the above-mentioned writing just want to express the relationship between the arguments and function parameters, the actual development process or recommend the following, the function appears to be more in line with the written habit, in the call parameters can also see the parameters need to pass

function Sayhi (name, type) {        console.log (' Hello, ' + name, type);    }    Sayhi (' Hang San ', ' SB ');  Hangsan  SB

  

JavaScript Learning Note 1

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.