逗号运算笔记

逗号运算符,它将先计算左边的参数,再计算右边的参数值。然后返回最右边参数的值。但是它的优先级别最低。

举个例子:

 
<script>
var a = 10, b = 20;
 
function CommaTest(){
return a++, b++, 10;
}
 
var c = CommaTest();
 
alert(a); // 返回11
alert(b); // 返回21
alert(c); // 返回10
 

</script>

猜你喜欢

转载自www.cnblogs.com/sweeeper/p/8994018.html