Because there is no block-level scope in ECMAScript , variables defined inside the loop can also be accessed externally to the
// For example: var count = ten; for (var i = 0; i < count; i++//
For-in Statements
The for-in statement is a precise iterative statement that can be used to enumerate the properties of an object. The following is the syntax for the for-in statement:
For (property in expression) statement
Here is an example:
for (var propname in window) {
document.write (propname);
}
In this example, we use theFor-inLoop to show theBomInWindowAll properties of the object. Each execution loop
, you'llwindow propname all properties in the object are enumerated again. Similar to the for statement, here control the var operator is also not required. However, in order to ensure the use of local variables,
We recommend this approach in the example above.
ecmascript The properties of the object are not in order. Therefore, the order of the property names that are output by for-in Specifically, all properties are returned once, but the order in which they are returned may vary depending on the browser.
However, if the variable value that represents the object being iterated is null for-in The statement throws an error.
ecmascript 5
compatibility, it is recommended to detect that the value of the object is not fontstyle2 before using loop class= "Fontstyle2" >null undefined
/span>
label statement
use label statement you can add tags to your code for future use. The following is the syntax for label statement:
label:statement
Below is an example:
start:for (var i=0; i < count; i++) {
Alert (i );
}
This example defines start tags can be used in the future by break or continue Statement reference. Tagged statements are generally
to for statements are used in conjunction with the Loop statement.
/span>
JavaScript Advanced Program Design reading notes (iv)