1.string—>number

  1. 只能识别纯数字的字符串,其它字符输出NaN
  2. 示例:var str ="3";
  3. var num = Number(str);
  4. console.log(typeof num)
  5. console.log(Number("3.0"))
  6. console.log(Number("3.00"))
  7. console.log(Number("3px"))//Nan 不是一个数字的意思

2.boolean—>number

  1. Number()
  2. 只有两种输出方式:true--1;false--0;
  3. 示例:var b = true;
  4. var f = false;
  5. console.log(Number(b));
  6. console.log(Number(f));

3.string—>boolean

  1. Boolean()
  2. “”为false(也就是“”之间不加任何东西),其他都为true
  3. 示例:var str = "good";
  4. var s = "";
  5. var t = "";
  6. console.log(Boolean(str));
  7. colnsole.log(Boolean(s));
  8. console.log(Boolean(t));

4.number—>boolean

  1. 只有0false,其他情况都为true
  2. 示例:var num = 0;
  3. var n = -1;
  4. var m = 1;
  5. cosole.log(Boolean(num));
  6. consol.log(Boolean(n));
  7. console.log(Boolean(m))

5.any—>string

  1. number,boolean--string
  2. toString()
  3. 示例:var num = 10;
  4. var t =true;
  5. console.log(String(num))
  6. console.log(t.toString)

6.any—>number

  1. string-->number
  2. 1.能够识别纯数字的字符串
  3. 2.""," ",识别成0
  4. 3.NaN
  5. boolean--number
  6. true 1
  7. false 0