1 Star 0 Fork 0

叶建华/js-base-day2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
03-隐式转换.html 1.60 KB
一键复制 编辑 原始数据 按行查看 历史
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>隐式转换</title>
</head>
<body>
<script>
// // 第一个数字
// let num1 = +prompt('请输入第一个月工资:')
// // // 第二个数字
// let num2 = +prompt('请输入第二个月工资:')
// // // 输出结果
// alert(num1 + num2)
// 1. 隐式转换为数字型的运算符
// 1.1 算术运算符 - * / % 比较运算符 > ==
// console.log('10' - '5') // 5
// console.log(10 - '50px') // NaN
// console.log(10 * '100') // 1000
// console.log('10' + 10) // 1010
// console.log(100 > '10') // true
// console.log(100 == '100') // true
// 1.2 + 正号使用的时候,也会把字符串转换为 数字型
// console.log(typeof +'100')
// console.log( +'100px')
// 2. 隐式转换为字符串型的运算符
// + 运算符左边或者右边只要有个是字符串, 都会转成字符串来拼接
// console.log(10 + '10') // '1010'
// console.log('abc' + 100) // 'abc100'
// console.log('' + 10086) // '10086'
// 3. 隐式转换为布尔型的运算符 !逻辑非
// 0 '' undefined null NaN false
console.log(!0) // true
console.log(!'') // true
console.log(!undefined) // true
console.log(!null) // true
console.log(!NaN) // true
console.log(!false) // true
console.log(!'abc') // false
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/yjh8866/js-base-day2.git
git@gitee.com:yjh8866/js-base-day2.git
yjh8866
js-base-day2
js-base-day2
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385