考虑下面的代码:的javascript:运营商之间的回报值差 - 和 - =
var x = 0;
function decrement(num) {
return num--;
}
var y = decrement(x);
console.log(y); // 0
对战如下:
var x = 0;
function decrement(num) {
return num -= 1; // this is the only difference between the functions
}
var y = decrement(x);
console.log(y); // 0
为什么从功能y--
回报0
不同时y -= 1
回报-1
?
我很好奇,为什么你也没有运行' - y';但你可能会在这个问题中找到答案:http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript –
@DavidThomas谢谢。没有意识到你不能在SO上轻松搜索单个字符。会解释为什么我一开始就找不到这个问题的答案。 – dtburgess
而不是使用Stackoverflow作为参考,尝试使用实际参考作为参考:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators – Jan