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