Convert in Primitive Type

1.Covert to Boolean

以下值会被转为false :

  • null
  • undefined
  • 0
  • -0
  • NaN
  • ""
[JavaScript]
var bl= !(!(null));
console.log(bl);  //=> "false"

2.Covert to Number

  1. 以数字表示的字符串可以直接转换为数字,允许开始或结尾处带有空格,如“123”、“ 123.45 ”
  2. 空格在数字中间,将造成字符串转为NaN,如“123 45”
  3. 含有非数字字符的字符串,将造成字符串转为NaN,如“123T45”
[JavaScript]
var num = +"123.45";
console.log(num);  //=> 123.45
num = +"  123.45  ";
console.log(num);  //=> 123.45
num = +"123 45";
console.log(num);  //=> NaN
num = +"123T45";
console.log(num);  //=> NaN

3.Covert to String

你可能感兴趣的:(Convert in Primitive Type)