"JavaScript advanced Programming" reading notes (iv)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.