zoukankan      html  css  js  c++  java
  • JS数据类型

    Javascript 布尔值

    布尔值只有两个值:true或false

    实例:

    var x = true;

    var y = false;

    typeof 运算符

    您可使用Javascript 的typeof 来确定Javascript 变量的类型:

    typeof 运算符返回变量或表达式的类型:

    实例:

    typeof ""                           //返回 "string"

    typeof "Bill"                       //返回 "string"

    typeof "Bill Gates"                 //返回 "string"

    typeof 运算符对数组返回"object",因为在JavaScript中数组属于对象

    Undefined

    在Javascript中,没有值的变量,其值是undefined.typeof也返回 undefined.

    var person;                         //值是 undefined,类型是 undefined

    任何变量均可通过设置为 undefined 进行清空.其类型也将是 undefined.

    person = undefined;                 //值是 undefined,类型是 undefined

    空值

    空值与 undefined 不是一回事

    空的字符串变量既有值也有类型。

    var car = "";                       //值是 "",类型是"string"

    Null

    在 Javascript 中, null 是 "nothing".它被看做是不存在的事物.

    不幸的是,在JavaScript中,null的数据类型是对象.

    您可以把null在JavaScript中是对象理解为一个bug.它本应是null.

    您可以通过设置值为null清空对象:

    var person = null;                  //值是 null,但是类型仍然是对象

    您也可以通过设置值为 undefined 清空对象:

    var person = undefined;             //值是 undefined,类型是 undefined

    Undefined 与 Null 的区别

    Undefined 与 null 的值相等,但类型不相等:

    typeof undefined                   //undefined

    typeof null                        //object

    null === undefined                 //false

    null == undefined                  //true

    原始数据

    原始数据值是一种没有额外属性和方法的单一简单数据值

    typeof 运算符可返回以下原始类型之一:

    ·string

    ·number

    ·boolean

    ·undefined

    实例

    typeof "Bill"                     //返回"string"

    typeof 3.14                       //返回"number"

    typeof true                       //返回"boolean"

    typeof false                      //返回"boolean"

    typeof x                          //返回"undefined"(假如 x 没有值)

  • 相关阅读:
    vue改变了数据却没有自动刷新
    Unable to find vcvarsall.bat
    修改Linux用户配置之后先验证再退出
    平面最远点对
    [转]你可能不知道的五个强大HTML5 API
    sqlite3常用技巧
    使用rsync
    画图必备numpy函数
    np.percentile获取中位数、百分位数
    [转]numpy 100道练习题
  • 原文地址:https://www.cnblogs.com/wzy123/p/11342004.html
Copyright © 2011-2022 走看看