JS self-executing function, call recursive function, parentheses operator, function declaration promotion

Source: Internet
Author: User

Objective

The cause is that I want to be in jquery Ajax to decide whether or not to proceed with the AJAX request based on the return value, which is a conditional loop that pops out of the condition. You can use the while loop, but it's good to think about it or to call it recursive.

Call a recursive function

The recursive function is probably the case. Do not meet the criteria to re-execute this function

    function f () {        // do something        if(1) {        }         Else{    f ();        }    }
Parentheses operators and self-executing functions

The parentheses operator in JS refers to (), which generally has two functions.

1, immediately after the function to execute this function, such as f ()

2, calculate the expression, such as

// Print 2(1+1)

Calculates a function based on () calculating the effect of an expression

// returns the function itself (function () {// do something})

Execute the function immediately after () followed by the function

// returns the function itself (function () {// do Something}) ()

Of course, what parameters are required for a function, and () What arguments are passed, as in normal function execution

Elevation of function declarations

In general, the JS execution order is ordered, and the variable will return undefined if it is not declared, but it can be used before declaring a function () {}, because JS will take precedence over the code that declares the function.

JS self-executing function, call recursive function, parentheses operator, function declaration promotion

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.