JavaScript Functions-notes

Source: Internet
Author: User

1. When a function is defined, no return value can be returned. If no return value is specified, the function returns an undefined value;

2. The function stops and exits immediately after the return statement is executed. Therefore, the statements following the statement will not be executed;

3. A function can contain multiple return statements, such ...... Else ...... Medium

4. The return statement can return undefined without any return values. This method is generally used when you need to stop the function in advance and do not need to return values.

5. The ecmascript function does not limit the number and type of parameters passed in. The reason is that the parameters in the ecmascript function are represented by an array internally, the function always receives this array. No matter what the array contains, in the function body, you can access this parameter array through the arguments object to obtain each passed parameter. [The arguments object is not an array, but an array. You can use square brackets to access each element]

6. determine the number of parameters passed in by the function, which can be obtained through arguments. length;

7. There is no overload in ecmascript (the function signature does not exist). You can use arguments. length to determine the number of input parameters. Then, different programs are executed to simulate overload;

8. The length of the arguments object is determined by the passed parameters, not the number of named parameters when defining the function;

9. A named parameter without passing a value will be assigned an undefined value, with a defined variable but not initialized;

10. All parameters in ecmascript pass values, and it is impossible to pass parameters through references;

11. The value of arguments is always synchronized with the value of the corresponding named parameter. However, they are independent and exist in different memory spaces. In addition, this synchronization is unidirectional, modifying the value of an element in arguments will affect the value of the corresponding named parameter, but the value of the arguments element of the object that modifies the value of the named parameter will not be affected;

12. Functions in ecmascript are actually objects. Each function is a function-type instance and has attributes and methods like other reference types;

13. The function is an object. Therefore, the function name is actually a pointer to the function object and is not bound to an object. [The function is an object, and the function name is a pointer ];

14. A function may have multiple names, just like other variables containing object pointers, because the function name is only a pointer to the function;

15. The function name without parentheses is the access function pointer, and the function name with parentheses is the call function;

16. function declaration and function expression:

① When the parser loads data to the execution environment, it will first read the function declaration and make it available before executing any code, function expressions can be parsed and executed only when the parser executes the code to which it is located;

② In addition to the differences between variable-based function access, the syntax of function declaration and function expression is equivalent;

③ The function name is a variable, so the function can also be used as a value. Not only can the function be passed as a parameter to another function, but can also be used as the return value of another function;

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.