3.6语句

本文介绍了JavaScript中常用的循环及控制语句,包括if、do...while、while、for、for...in等,并讨论了标签(label)、break与continue的使用场景及注意事项。

语句

if语句 (推荐花括号包起来)
do white (先执行一次,再判断)
white (先判断,再执行)
for (循环内部的变量,外部也可以访问到,没有块级作用域)
for in (枚举对象属性值,建议先检测是不是null或者undefined)
label (Labels are not very commonly used in JavaScript since they make
programs harder to read and understand. As much as possible, avoid
using labels and, depending on the cases, prefer calling functions or
throwing an error.)(难读懂,尽量不经常使用)
break continue 跳出循环
with 作用域作用在一个对象上(严格模式不允许使用)
switch 不一定是常量,也可以是变量,或者表达式

for while

var count = 10;
for(var i = 0; i < count; i++){
    l(i);
}

var count = 10;
var i = 0;
while(i < count){
    console.log(i);
    i++;
}

转载于:https://www.cnblogs.com/caijw/p/8038032.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值