Declaration of the javascript--function and the Order of code execution in the call/js

Source: Internet
Author: User

[Declaration and invocation of functions] 1. Function declaration format:Function name (parameter 1, parameter 2, Parameter 3 ...) {//function body return result;} function call format: function name (value of parameter 1, value of parameter 2, ...) ; event Invocation: Event name = function name (); 2, the function declaration of several emphasis:The declaration of the ① function must conform to the small hump rule (first letter lowercase, followed by the first letter of each word); The list of ② parameters, which can have parameters, can have no parameters. Respectively called the parameter function, the parameterless function, ③ the argument list when declaring a function, called the "parameter list" (the name of the variable), the parameter list when invoking the function, called the "argument list" (the value of the variable);  ④ function If a return value is required, return the result using a return. When the function is called, the value of the var variable = function name () is used to receive the returned result, and if the function does not return a value, the received result is undefined. The scope of variables in the ⑤ function: In the function, the variable declared with VAR, the default is the function local variable, only in the function content can be used, not the variable declared by VAR, the default is a global variable (global variable in the function, must be used after the function call to use) function parameter list, function local variable, only Within the function can be declared with the function call ⑥ function, there is no front and back points.   [JS in code execution order]JS in the code to run, will be checked, loaded, that is, declaring variables, functions and so on, and then in the execution phase, (the assignment of variables, etc. belong to the execution phase). Therefore, the declaration of a function belongs to the check loading stage, and the function invocation belongs to the execution phase. So, a function call statement does not have any relationship before it is written in a Kazakhstan declaration statement. So, the above code, perform an inflow-------check the load phase-------var num;//declare variable function func ()//Declare function-------Check the load stage-------console.log (num); num = 10 ; FuncN ();//execute the code in {} of the function "Declaration and invocation of anonymous functions" 1, declare an anonymous function, directly assigned to an event;Window.onload=function () {} 2, using function expressions, declaring anonymous functions;Declaring a function expression: var func = function () {} calls the functions expression: func () >>> use an anonymous function expression, then the call statement must be declared after the statement, otherwise an error (compared to the general function declaration and the call difference!) 3, using self-executing function, declare and invoke the anonymous function directly;!function () {} (); Start with any operator and use it normally! (function () {} ()); Use () to wrap the anonymous function and the following parentheses (function () {}) (); Use () parcel only anonymous function expressions >>>>> three writing features: ① structure is clear, the beginning of the addition! , End Plus (). Not easy to mess, recommended use; ② can indicate that the anonymous function and the following () are a whole, recommended to use; ③ cannot indicate that the function and after () are a whole, not recommended.

Declaration of the javascript--function and the Order of code execution in the call/js

Related Article

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.