数据类型转换

部分知识点

var a;
var b = a * 0;
// console.log(b); 输出NAN  
if (b == b) {
    // NAN != NAN
    console.log(b * 2 + "2" - 0 + 4);
} else {
    // NAN=false=0
    console.log(!b * 2 + "2" - 0 + 4); //!0*2+"2"-0+4
}

var a = 1;
console.log(a++); //1
console.log(++a); //3

console.log(null == undefined); //true
console.log("1" == 1); //true
console.log("1" === 1); //false

console.log(null == undefined); //true
console.log("1" == 1) //true
console.log("la" == 1) //false
console.log("ala" == 1) //false
console.log("1" === 1); //flase  ===全等于
parseFloat("3asdf"); //3
parseFloat("3.14asdf12"); //3.14
// parseFloat()函数 可以解析一个字符串 并返回一个浮点数
parseInt(3.14); //3
parseInt("1.23abc456"); // 1 
parseInt(true); //"true"=>NaN  这里将true看做了字符串 "true" => NaN 所以为false
// 验证方法  例:
var a = parseFloat("3asdf");
console.log(a);
复制代码

重点

null == undefined //true
undefined == 0; //false 把undefined想象成 一个自然数
null = '' //false
false == '' //true
// boolean类型跟其他类型 == 时,会转换成 Number 类型
// Number 类型跟String类型==时,string类型会转换成Number类型
undefined == false //false
udnefined == '' //false
    !undefined //true
    !null //true
    !'' //true
    !false //true
复制代码

转载于:https://juejin.im/post/5d0b8f1c5188250640007e94

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值