老师看下代码以及注释理解是否正确谢谢
来源:5-7 编程练习
yarwood
2020-08-13 00:05:56
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title> ++和--的运算</title>
</head>
<body>
<script>
var a=4,
b=5;
result1=(a++)+(--b);
result2=(a++)-(--b);
result3=(a++)*(--b);
result4=(a++)/(--b);
//每一次计算完num1、num2的值会被保留, 然后开始新的计算。
document.write(a+"<br>");//4+1+1+1+1=8,有4个a,所以要+4个1
document.write(b+"<br>");//5-1-1-1-1=1 同理
document.write(result1+"<br>");//4+(5-1)=8
//(单个显示是5 如rusult1=(a++)+(--b)这个时候,a++打印值是5)这里有2个a,原本第一个实际计算中值是4,那么第二个+1
document.write(result2+"<br>");//(4+1)+(4-1)=2
document.write(result3+"<br>");//(5+1)*(3-1)=12
document.write(result4+"<br>");//(6+1)/(2-1)=7
</script>
</body>
</html>
1回答
同学你好,代码以及注释都是正确的,很棒。继续加油,祝学习愉快!
相似问题