1. string,boolean—>number number()
只能识别纯数字字符串,其他字符输出 Nan
string转化number
<script>
/* string-->number number()
只能识别纯数字字符串,其他字符输出 Nan
*/
var str = "3"
var num = Number(str);
console.log(typeof num);
console.log(Number("3.0"));
console.log(Number("3.00"));
console.log(Number("3px")); //nan 不是一个数字的意思
</script>
boolean转化number
<script>
var a = true // 输出1
var b = false // 输出0
console.log(Number (a)) // 1
console.log(Number (b)) // 0
</script>
2. Number,string—>boolean
1.string-->boolean<br /> 特点:除了 "" 空字符-->输出为false,其他都为true。
var a ="good"
var b = " "
var c = ""
console.log(Boolean (a))
console.log(Boolean (b))
console.log(Boolean (c))
2.Number-->boolean<br /> 特点:除了 0-->输出为false,其他都为true。
var d =0
var e =1
var f =1
console.log(Boolean (d))
console.log(Boolean (e))
console.log(Boolean (f))
3. Number,boolean—>string
<script>
//String()
// tostring()
var num = 10
var b = true
console.log(String (num))
console.log(typeof b.toString() )
</script>
4. false
<script>
//String()
// tostring()
var num = 10
var b = true
console.log(String (num))
console.log(typeof b.toString() )
</script>