0
点赞
收藏
分享

微信扫一扫

JavaScript中的简单数据类型

婉殇成长笔记 2022-03-30 阅读 46
undefined 未定义  值:undefined
    (1)变量被声明了,但没有赋值时,就等于undefined。
    (2)  调用函数时,应该提供的实参没有提供,该形参等于undefined。
    (3)对象没有赋值的属性,该属性的值为undefined。
    (4)函数没有返回值时,默认返回undefined。
    (5) 当获取数组数据的下标超过数组的长度的时候,则该数据的值是undefined
null  空对象
    值:null
number 数字值:
    1)正常数字
    2)Infinity -Infinity
    3)NaN
    乘 除 减 取余  得到的结果一定是数字类型
    加    除了含有字符串之外 得到的也是数字
string 字符串
    值:加引号的
    + 在 字符串中起到拼接的作用
boolean 布尔值:true/false
    在运算中true是1  false是 0
    复杂数据类型(引用数据类型) 存在堆中
object 对象 值:无数
1.其他类型转为字符串
    1) 其他数据类型的值+''  
        比如 undefined+''   
            123+''
            true+''
            false+''
            null+''
    2) String(x)  x.toString();String(23);
2.其他数据类型转为 数字
    1) 其他数据类型-0   'abc'-0  true-0
    2) Number() parseInt() parseFloat()
    undefined 转为 NaN
    null  转为  0
    object 转为 NaN
    true  转为 1
    false 转为 0
    ''  或者 '    '  转为 0
    非空字符串  只要含有字母 Number方法 转为 NaN    
    parseInt/parseFloat  如果数字开头 转为相应的数字
3.其他数据类型转为 布尔 Boolean()  
    undefined  转为 false
    null    转为 false
    object  转为 true
    非0转为true,0和NaN转为false
    非空字符转为true,空字符串转为false
举报

相关推荐

0 条评论