parseInt() 和Number() 的区别
parseInt() 是一个字符串一个字符串的解析 返回的是整数(不四舍五入)如果123adc 返回123
Number转换的值必须是存字符串 如果adc123 返回NaN
<font color="red">
带parse 开头 对于解析都是一个一个解析的
![](https://img.haomeiwen.com/i16719466/1a18a96a790c6033.png)
自动转换
![](https://img.haomeiwen.com/i16719466/978ed88cd7ac9819.png)
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script type="text/javascript">
var a=123;
var b=true;
c=String(a);
d=String(b);
console.log(c);
console.log(d);
console.log(typeof c); //String
console.log(typeof d);//String
//转换boolean
var x=false;
x=Boolean(x);
console.log(x);
console.log(typeof x);// 变成boolean
//自动转换 为number 自动是说运算的时候自动转换,原始变量并不是转换成本身
var a="123";
a= +a;
console.log(a);
console.log(typeof a);
</script>
</head>
<body>
</body>
</html>
网友评论