为什么避免在 JavaScript 中使用增量 (“++”) 和递减 (“--”) 运算符?
应避免使用增量和递减运算符,因为它可能导致意外结果。以下列出了一些条件
在赋值语句中,它可能导致不必要的结果
示例
<html>
<body>
<script>
var a = 5;
var b = ++a; var c = a++;
var d = ++c;
document.write(a);
document.write("\r"+b);
document.write("\r"+c);
document.write("\r"+d);
</script>
</body>
</html>输出
运算符和变量之间的空白也可能导致意外结果
a = b = c = 1; ++a ; b -- ; c;
广告
数据结构
网络
关系数据库管理系统(RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP