zoukankan      html  css  js  c++  java
  • JS 常用的数据类型(二)

    基本数据类型

    引用数据类型

    • 对象数据类型 object
          普通对象:用{ } 存放数据
          数组对象:用[ ] 存放数据
          正则对象
    • 函数数据类型 function

    1. 布尔类型Boolean
    包含:true和false
           1.1 其他类型类型值转换为布尔类型
           只有0,NaN,’ ',null,undefined 五个值转换为false,其余都转换为true(而且没有任何的特殊情况)

    console.log(Boolean(''))   // false
    console.log(Boolean(null)) // false
    console.log(Boolean(NaN))  // false
    console.log(Boolean(0))	   // false
    console.log(Boolean(undefied))  //false
    
    console.log(Boolean(' '))  // true
    console.log(Boolean([]))   // true
    console.log(Boolean(-1))   // true
    

          1.2 ! 和 !!的作用
           !:取反(先转为布尔,然后取反)
           !!:取反再取反,只相当转换为布尔。即:!! <==> Boolean

    console.log(!1)   		 //false
    console.log(!!1)  		 //true
    console.log(Boolean(1))  //true
    

          在条件判断中,不是==/===/!=/>= 等这些比较,是要把这个值先转换为布尔类型,然后验证判断是否可以通过。

    2. null 和 undefined
    简介:null和undefined都代表没有,术语:值的空缺
           2.1 null
           null一般是开始在申明变量时不知道值,我们手动先设置为null,后期再给予赋值操作,在申明值时不赋值为null也可以,可以赋值变量为""或者为0,但赋值为null会节省栈内存空间。

           2.2 undefined
           undefined不同于null可以事先赋值,当创建一个为赋值的变量就是undefined。

    let num;
    console.log(num) // undefined
    

           2.3 null和undefined有啥区别
           上面两点说的好像没啥用,理解下来就是null和undefined都是空值,没什么区别。下面引入JavaScript创建null和undefined本意:undefined是表示系统级的、出乎意料的或类似错误的值的空缺,而null是表示程序级的、正常的或在意料之中的值的空缺。

  • 相关阅读:
    串的动态存储分配
    队列的链式表示
    堆栈相关知识
    函数参数的传值与传址
    js原生实现getElementsByClassName
    js原生复杂实现animate操作Css3属性(升级版!)
    在 CentOS 6 上安装 PHP 5.4.30
    CentOS 更改MySQL数据库目录位置
    使用X-UA-Compatible来设置IE浏览器兼容模式.
    __set() And __get() 使用详解.
  • 原文地址:https://www.cnblogs.com/wangqilong/p/12540348.html
Copyright © 2011-2022 走看看