JavaScript中类型转换中“ +”运算符的重要性是什么?
'+'运算符有很多用途,包括加法,串联和最重要的类型转换。通常,我们使用'+'运算符进行加法,有时使用级联。它在类型转换中也有很多用途。将字符串转换为数字非常容易。
示例
<html>
<body>
<script>
var num = "23";
int = +num;
document.write(int);
document.write("</br>");
document.write(typeof int);
</script>
</body>
</html>输出
23 number
不仅类型转换,此运算符还用于将布尔值 转换为数字。它将布尔值(例如true 或false) 分别更改为1和0。
示例
<html>
<body>
<script>
document.write(+true);
document.write("</br>");
document.write(+false);
</script>
</body>
</html>输出
1 0
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短