1-1 string,boolean —> number

  1. var str = 'w';
  2. var num = Number(str);
  3. console.log(typeof num);
  4. console.log(Number('3.0'));
  5. console.log(Number('3.00'));
  6. console.log(Number('3px')); //NaN 不是一个数字
  7. // 1.能够识别纯数字的字符串
  8. // 2.""," " 识别成0
  9. // 3.NaN

1-2 boolean—> number

  1. // true = 1; false = 0;
  2. var a = true;
  3. var b = false;
  4. console.log(Number(a));
  5. console.log(Number(b));

1-3 string,number —-> boolean

  1. // string,number ---> boolean
  2. // Boolean();
  3. // string --> boolean 特点:'' 没有空格的空字符串为false,其他都为true
  4. var str = 'good'
  5. var s = ' '
  6. var t = ''
  7. console.log(Boolean(str));
  8. console.log(Boolean(s));
  9. console.log(Boolean(t));

1-4 number —> boolean

  1. // number --> boolean
  2. // tips:是只有0为false,其他情况都为true
  3. var num1 = 0
  4. var n = -1
  5. var m = 1
  6. console.log(Boolean(num));
  7. console.log(Boolean(n));
  8. console.log(Boolean(m));

1-5 number,boolean —> string

  1. numberboolean --> string
  2. // String();
  3. var num1 = 10
  4. var t = true
  5. console.log(String(num1));
  6. console.log(String(t));

1-6 转化结果为:false

  1. // 转化结果为:false
  2. // number -- 0
  3. // string -- ""
  4. // unfefined
  5. // NaN