JS语法学习实战- 流程控制

JS语法学习实战- 流程控制

  • 1. if - else
  • 2. switch
  • 3. for循环
  • 4. while循环
  • 5. 更多

1

JS语法学习实战系列合集

1. if - else

if (条件1){
    条件1成立之后执行的代码
}else if(条件2){
    条件2成立之后执行的代码
}else{
    条件不成立之后执行的代码
}

2. switch

var day=new Date().getDay();
switch (day) {
    case 0:
    console.log('Sunday');
    break;
    case 1:
    console.log('Monday');
    break;
    case 2:
    console.log('Tuesday');
    break;
    default:
    console.log('暂时不提供该定义')
}

3. for循环

for(let i=1;i<100;i++){
    console.log(i)
}
#示例:打印下列数组中所有的值
l1 = [1,2,3,4,5,6,7,8,9]
for(let i=0;i

4. while循环

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

5. 更多

JS语法学习实战系列合集

你可能感兴趣的:(前端,javascript,学习,前端)