label语句和break continue的使用(高程第三章)

 

 1 break&&outermost
 2 var num = 0;
 3 outermost:
 4 for(var i=0;i<10;i++){
 5   for(var j=0;j<10;j++){
 6     if (i==5&&j==5) {
 7       break outermost;
 8     }//i=5 j=4
 9     num++
10   }
11 }
12 console.log(num);//55

2:continue&&outermost  这种情况下会退出内部循环,执行外部循环,也就意味着内部循环少执行了5次

var num = 0;
outermost:
for(var i=0;i<10;i++){
    for(var j=0;j<10;j++){
        if (i==5&&j==5) {
            continue outermost;
        }
        num++
    }
}
console.log(num);//95

3:switch case语句,假如有多个if else 用switch case可以精准定位到满足条件的语句,性能好

var num = 10;
switch (num){
    case "10":
        console.log("小于0");
        break;
    case 10:
       console.log("执行的是全等操作");
       //break;
       //没有break继续往下执行
    case num==10:
        console.log(10);
        break;//答案为 "执行的是全等操作"&&10
    case num > 10:
        console.log("10");
        break;    
    default:
        console.log("100");
}

4:通过arguments对象的length属性可以获知有多少个参数传递给函数,arguments对象只是与数组类似,并不是Array实例

function add(){
    console.log(arguments.length);
}
add(10,20);//2
add(10)//1

function doAdd(num1,num2){
    "use strict";//严格模式下值为28;也就是说无法改变本身带的参数值
    arguments[1] = 10;//非严格模式下值为18
    console.log(arguments[0]+num2);
}
doAdd(8,20)//28

 

posted @ 2016-09-25 15:33  overAgain  阅读(216)  评论(0编辑  收藏  举报