zoukankan      html  css  js  c++  java
  • (四)JavaScript之[break和continue]与[typeof、null、undefined]

    7】、break和continue

     1 /**
     2 * JavaScript 的break和continue语句
     3 * break 跳出switch()语句
     4 * break 用于跳出循环
     5 * continue 用于跳过循环中的一个迭代*/
     6 
     7 // break 跳出循环
     8 for(var i = 0;i < 10;i++){
     9     if(i == 3){
    10         break;
    11     }
    12     console.log('The number is: ' + i);
    13 }
    14 
    15 // continue 跳过循环
    16 for(var i = 0;i < 10;i++){
    17     if(i == 3){
    18         continue;
    19     }
    20     console.log('The number is: ' + i);
    21 }
    22 
    23 /**
    24 continue 语句(带有或不带标签引用)只能用在循环中。
    25 break 语句(不带标签引用),只能用在循环或 switch 中。*/
    26 
    27 //通过标签引用,break 语句可用于跳出任何 JavaScript 代码块:
    28 var myCar = ['car1', 'car2', 'car3', 'car4', 'car5'];
    29 
    30 list: {
    31     console.log(myCar[0]);
    32     console.log(myCar[1]);
    33     console.log(myCar[2]);
    34     break list;
    35     console.log(myCar[3]);
    36     console.log(myCar[4]);
    37 }


    8】、typeof、null、undefined

     1 /**
     2 * typeof操作符检测变量的数据类型
     3 *
     4 * Null
     5 * null 表示空对象的引用
     6 * typeof null为 object
     7 *
     8 * Undefined
     9 * undefined 是一个没有设置值的变量
    10 * 任何变量都可以设置值为undefined来清空
    11 *
    12 * Undefined和Null的区别*/
    13 
    14 console.log(typeof('John'));//string
    15 console.log(typeof(3.14));//number
    16 console.log(typeof(false));//boolean
    17 console.log(typeof([1,2,3,4]));//object,数组是一种特殊的对象类型
    18 console.log(typeof({name: 'John', age: 34}));//object
    19 
    20 //Undefined和Null的区别一:
    21 console.log(typeof(null));//object
    22 console.log(typeof(undefined));//undefined
    23 
    24 var person = 'lqc';
    25 //设置为null来清空对象
    26 person = null;
    27 
    28 //设置为undefined来清空对象
    29 person = undefined;
    30 
    31 var person2;
    32 console.log(person2);//undefined
    33 
    34 //Undefined和Null的区别二:
    35 console.log(undefined == null);//true
    36 console.log(undefined === null);//false
  • 相关阅读:
    SWT的TableVierer的使用二(数据排序)
    SWT的TableVierer的使用一
    SWT的TreeVierer的使用
    SWT中一些细节的说明
    SWT中各种参数大全
    SWT的GridLayout一些参数解释
    SWT中的GridLayout(转)例子不错
    鼠标放到按钮上,实现的动画
    关于文字下方线消失的动画
    超出部分用省略号代替,鼠标放上去显示多余部分内容
  • 原文地址:https://www.cnblogs.com/lqcdsns/p/5331173.html
Copyright © 2011-2022 走看看