JS executes the function immediately, (). The previous function is an expression and cannot be a function declaration

Source: Internet
Author: User

FnName (); function fnname() {...} //Normal, because ' Ascend ' function declaration, function call can be before function declaration

< Span class= "hljs-function" >fnname (); var fnname=function (//error, variable fnname has not saved a reference to the function, the function call must be after the function expression

var fnname= function () {     alert ( ' Hello world ');} (); //function expressions are appended with parentheses, and can be called immediately when the JavaScript engine resolves here

< Span class= "Hljs-keyword" >< Span class= "Hljs-params" >function   Fnname ( {    alert ( ' Hello world ');} (); //will not error, but the JavaScript engine only resolves function declarations, ignoring subsequent parentheses, function declarations are not called

Function ( {    console.log ( ' Hello World ' );    } (); //syntax error, although anonymous function is a function expression, but no assignment operation, // So the JavaScript engine takes the function keyword at the beginning as a functional declaration, an error: Requires a name for the functions

JS executes the function immediately, (). The preceding function is an expression and cannot be a function declaration

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.