有什么区别:
例 1。
<script type="text/javascript">
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
</script>
例 2。
<script type="text/javascript">
{
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
}
</script>
W3C 学校表示:
Ex 1. Each statement is executed by the browser in the sequence they are written.
Ex 2. The purpose of a block is to make the sequence of statements execute together.
请解释一下上述说法。浏览器对上述命令有何不同的 react ?
最佳答案
完全没有区别, block 的目的是在 ifs 和 fors 中使用,如下所示:
示例 1 如果 () //要执行的命令
示例 2 如果 () { //要执行的许多命令 }
在第二个示例中,if 语句将 block 命令“视为”单个命令,在 block 内,命令仍然按顺序执行。
关于javascript - 不同的 JavaScript block 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6520594/