本帖最后由 浪淘沙 于 2011-5-15 16:29 编辑
回复 70# 伴月星辰
再来一段代码,看看为何是这种结论:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<script>
document.write("<H5>"+"6/2*(1+2)= " + 6/2*(1+2) +"</H5>" );//请试着把乘号“ * ”省略,看看是什么结果?
a=6;
b=2;
c=1;
document.write("<H5>计算前"+"a=" + a + "," + "b=" + b + "," + "c=" + c + "," +"</H5>" );
d=a / b* (c+ b);
e=a++ / b++ * (c++ + b++);
document.write("<H5>"+"d=a/b * (c+b)= " +d+"</H5>" ); //计算得出d为9
document.write("<H5>"+"e=a++ / b++ * (c++ + b++)= " +e+"</H5>" ); //我想了很久才明白了e是12
document.write("<H5>计算后"+"a=" + a + "," + "b=" + b + "," + "c=" + c + "," +"</H5>" );
document.close();
</script>
</body>
</html>
程序的输出如下:
6/2*(1+2)= 9
计算前a=6,b=2,c=1,
d=a/b * (c+b)= 9
e=a++ / b++ * (c++ + b++)= 12
计算后a=7,b=4,c=2, |