1. string,boolean—>number number()

  1. 只能识别纯数字字符串,其他字符输出 Nan
  1. string转化number
  2. <script>
  3. /* string-->number number()
  4. 只能识别纯数字字符串,其他字符输出 Nan
  5. */
  6. var str = "3"
  7. var num = Number(str);
  8. console.log(typeof num);
  9. console.log(Number("3.0"));
  10. console.log(Number("3.00"));
  11. console.log(Number("3px")); //nan 不是一个数字的意思
  12. </script>
  1. boolean转化number
  2. <script>
  3. var a = true // 输出1
  4. var b = false // 输出0
  5. console.log(Number (a)) // 1
  6. console.log(Number (b)) // 0
  7. </script>

2. Number,string—>boolean

  1. 1.string-->boolean<br /> 特点:除了 "" 空字符-->输出为false,其他都为true
  1. var a ="good"
  2. var b = " "
  3. var c = ""
  4. console.log(Boolean (a))
  5. console.log(Boolean (b))
  6. console.log(Boolean (c))
  1. 2.Number-->boolean<br /> 特点:除了 0-->输出为false,其他都为true
  1. var d =0
  2. var e =1
  3. var f =1
  4. console.log(Boolean (d))
  5. console.log(Boolean (e))
  6. console.log(Boolean (f))

3. Number,boolean—>string

  1. <script>
  2. //String()
  3. // tostring()
  4. var num = 10
  5. var b = true
  6. console.log(String (num))
  7. console.log(typeof b.toString() )
  8. </script>

4. false

  1. <script>
  2. //String()
  3. // tostring()
  4. var num = 10
  5. var b = true
  6. console.log(String (num))
  7. console.log(typeof b.toString() )
  8. </script>