码迷,mamicode.com
首页 > 其他好文 > 详细

数据类型与数据类型转换

时间:2019-10-01 20:50:38      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:date   fine   block   ble   字符   span   als   lis   focus   



基本数据类型

  • 数字number
  • 字符串string
  • 布尔boolean
  • null
  • undefined
?
?

引用数据类型

  • 对象
    • 普通对象Object
    • 数组对象Array
    • 正则对象RegExp
    • 日期对象Date
    • ...
  • 函数function
  • ...

特殊类型

?

symbol,表示唯一值

var a = Symbol(‘abc‘); 
var b = Symbol(‘abc‘); 
console.log(a==b); =>false

 

把其他类型转换为数字(Number)

  • Number(字符串)

Number(‘13‘); ->13
Number(‘13px‘); ->NaN //遇到非有效数字结果为NaN 
Number(‘13.5‘); ->13.5 //可以识别小数

 

  • Number(布尔)

Number(true); //->1 
Number(false); //->0

 

  • Number(null和undefined)

    Number(null); //->0 
    Number(undefined); //->NaN

     

  • Number(引用类型):先把引用值调取toString转换为字符串,然后再Number该字符串转换为数字.

  • parseInt和parseFloat

    parseInt(‘13.5px‘); //=>13 
    parseFloat(‘13.5px‘); //=>13.5
    parseInt(‘px123‘);//NaN

把其他类型转换为布尔(Boolean())

规律:转换为false的只有0/NaN/空字符串/null/undefined,其余为true。

 

数据类型与数据类型转换

标签:date   fine   block   ble   字符   span   als   lis   focus   

原文地址:https://www.cnblogs.com/wangshouren/p/11615818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!