JS的布尔值类型
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var ret = 2 > 1
console.log(ret,typeof ret) // true 'boolean'
var ret2 = 2 == 1
console.log(ret2,typeof ret2) // false 'boolean'
var ret3 = 2 == "2"
console.log(ret3,typeof ret3) // true 'boolean' #JS自动将“数字2”转换为“字符串2”再比较
var ret4 = 2 === "2" // 取消JS的默认将“数字”转换为“字符串”功能
console.log(ret4,typeof ret4) // false 'boolean'
console.log(1 + "2") // 12 +的功能将前一个值和后一个值进行合并输出
console.log(1 - "2") // -1 -的功能将前一个值减去后一个值进行输出
</script>
</head>
<body>
<h1>welcome to JS!</h1>
</body>
</html>
标签:console,log,布尔值,JS,var,boolean,typeof,类型 来源: https://www.cnblogs.com/A121/p/16335447.html