Array cannot use the ForEach () method

Source: Internet
Author: User

Problem Description:

The structure of the function is as shown in the browser error when invoking the function:

Analysis Reason:

In JS syntax, if a statement is exclusive to a line, you can usually omit the semicolon at the end of the sentence

But in fact, when the JS parsing code, only in the end of the sentence is missing a semicolon will not work properly, will automatically fill the semicolon

If the statements in front and back can form a syntactically correct statement, the semicolon is not automatically filled

In the above function, JS actually handles the code as:

function Test (A, B, c) {  var x = A + b[a, B, C].foreach (function (e) {    // ) . ..   })}

In general, if the statement begins with "(", "[", "/", "+", "-" , the statement is most likely resolved with the previous statement

However, if the statement starts with "+ +" or "--", it takes precedence as the prefix operator for parsing

The statement will be parsed to x; ++y instead of + x; y

In addition, if the statement ends with return, continue, and break, JS will automatically fill the semicolon at the newline.

Solution:

Add a semicolon manually at the end of a statement

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.