网易微专业-JS06语句

Q1:while和do-while中的例子去掉“i++”逻辑上也是可行的,为何调试面板刷新时间大大延长,什么原因造成了内存的巨大损耗??

网易微专业-JS06语句_第1张图片
Paste_Image.png

1、条件语句
①if(条件){语句}

②if(条件){语句}else if(条件){语句}else{语句}

③switch(表达式){
case 值1:语句
break;
case 值2:语句
break;
default:语句
}

2、循环语句
①while

var i = 1;
  while(i <= 10){
    document.write(i);
    i++;
  }```

②do-while

var i = 11;
do{
document.write(i);
i++;
}while(i <= 10)//11```

③for
for(初始化;循环条件;更新表达式){语句}

for(var i=0;i<=10;i++){
document.write(i);
}```

注意:break vs. continue

![break跳出循环;
continue跳出本次循环](http://upload-images.jianshu.io/upload_images/316258-6f893f3d25e10c2b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

④for-in
for(属性名in对象){语句}

![Paste_Image.png](http://upload-images.jianshu.io/upload_images/316258-dd2de7be5c42a351.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)





3、with

![Paste_Image.png](http://upload-images.jianshu.io/upload_images/316258-40ac3f0eb428473c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


4、异常捕获

try{
document.write(notDefined);
}catch(error){
console.log(error);
alert(error);
}finally{
alert('finally');
}```

你可能感兴趣的:(网易微专业-JS06语句)