一、数据类型


二、类型转换

2-1、parseInt()类型转换
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type = "text/javascript" src="index.js"></script>
</head>
<body>
</body>
</html>
index.js
var str="123";
console.log(str+1);
console.log(parseInt(str)+1);

index.js
var str1="abc";
if(isNaN(str1)==false){
console.log(parseInt(str1))
}else {
console.log("is error");
str1 = 0;
}

index.js
var str="123.654";
console.log(parseInt(str));
console.log(parseFloat(str));
console.log(Number(str));

2-2、Boolean()类型转换
针对字符串来讲,有内容就是true,没有内容就是false.
针对数字来讲,0是false,非0是true
var str="abc";
console.log(Boolean(str));

var str=null;
console.log(Boolean(str));

var str=0;
console.log(Boolean(str));

var str=1;
console.log(Boolean(str));

网友评论