1、强制数据类型转换
1-1 string,boolean—>number
1-1-1纯数字string—>number
特点:只能识别纯数字的字符串
Number(value)
var a = "10";
var str = "hello"
console.log(Number(a)) //10
console.log(Number(str)) //NaN 不是一个数字
console.log(Number("3.0")) //3
console.log(Number(undefined)) // NaN
1-1-2 boolean —>number
var t = true
var f = false
console.log(Number(t)); //1
console.log(Number(f)); //0
1-1-3、含有字符的string—>number
parseInt()
parseFloat()
var str = "12px"
var s = "12.34px"
console.log(parseInt(str));
console.log(parseFloat(s));
1-2 number,string—>boolean
1-2-1 number—boolean
Boolean()
0转换为false,其他都为true
1-2-2 string—>boolean
""为false,其他都为true
1-3 Any-String
String()
toString()
+""