zoukankan      html  css  js  c++  java
  • (原创)JavaScript高级程序设计--学习笔记003-Boolean 类型

    Boolean 类型

        该类型只有两个字面值: true 和 false 。

        各种数据类型及其对应的转换规则:

            数据类型                      转换为true的值                              转换为true的值

            Boolean                       true                                                false

            String                          任何非空字符串                              "" (空字符串)

            Number                      任何非零数字值(包括无穷大)      0和 NaN (参见本章后面有关NaN的内容)

            Object                        任何对象                                         null

            Undefined                  n/a①                                              undefined

        需要注意的是,undefined是转换为false,0也是转换为false,所以,在if进行数值判断时,需要额外小心,例如:

            function test( num ) {

                if ( !num ) return;

                ...

            }

           test();  // !num 为true,return;

           test( 0 );  // 虽然传递了数值0,但是 !num 为true,return;

            if ( !num ) 这个判断本身的目的可能是判断是否有传递数值,但是当传递了数值0时,也会被认为没有传递数值;

  • 相关阅读:
    数学+高精度 ZOJ 2313 Chinese Girls' Amusement
    最短路(Bellman_Ford) POJ 1860 Currency Exchange
    贪心 Gym 100502E Opening Ceremony
    概率 Gym 100502D Dice Game
    判断 Gym 100502K Train Passengers
    BFS POJ 3278 Catch That Cow
    DFS POJ 2362 Square
    DFS ZOJ 1002/HDOJ 1045 Fire Net
    组合数学(全排列)+DFS CSU 1563 Lexicography
    stack UVA 442 Matrix Chain Multiplication
  • 原文地址:https://www.cnblogs.com/wodehao0808/p/11770145.html
Copyright © 2011-2022 走看看