zoukankan      html  css  js  c++  java
  • 1、条件语句2、循环语句3、异常处理

    1、条件语句

    JavaScript中支持两个中条件语句,分别是:if 和 switch

    1  if(条件){
    2  
    3     }else if(条件){
    4          
    5     }else{
    6  
    7     }
     1   switch(name){
     2         case '1':
     3             age = 123;
     4             break;
     5         case '2':
     6             age = 456;
     7             break;
     8         default :
     9             age = 777;
    10     }

    2、循环语句

    JavaScript中支持三种循环语句,分别是:

    1 var names = ["alex", "tony", "rain"];
    2  
    3 for(var i=0;i<names.length;i++){
    4     console.log(i);
    5     console.log(names[i]);
    6 }
    1 var names = ["alex", "tony", "rain"];
    2 
    3 for(var index in names){
    4     console.log(index);
    5     console.log(names[index]);
    6 }
    while(条件){
        // break;
        // continue;
    }

    3、异常处理

     1 try {
     2     //这段代码从上往下运行,其中任何一个语句抛出异常该代码块就结束运行
     3 }
     4 catch (e) {
     5     // 如果try代码块中抛出了异常,catch代码块中的代码就会被执行。
     6     //e是一个局部变量,用来指向Error对象或者其他抛出的对象
     7 }
     8 finally {
     9      //无论try中代码是否有异常抛出(甚至是try代码块中有return语句),finally代码块中始终会被执行。
    10 }

    注:主动跑出异常 throw Error('xxxx')

  • 相关阅读:
    Cocos2dx-背景无限循环播放
    centos 7端口和防火墙
    图片裁剪
    spring-boot图片压缩
    vue cli简介
    spring-boot的配置(实时生效)
    spring-boot打成war包放入tomcat运行
    spring-boot上传图片并访问
    linux链接ssh
    mysql远程访问
  • 原文地址:https://www.cnblogs.com/shiluoliming/p/6514676.html
Copyright © 2011-2022 走看看