3. Function functions

Source: Internet
Author: User

A function, in essence, is a form of grouping of code. We can give a name to a group of code in this form, so that later reuse is called.

function sum (b) {    var c = A +b    ; return C;}

1. A function can have only one return value, and if we need to return more than one value at a time, consider putting it in an array and returning it as an array element.

2. We can create some functions that are more flexible in terms of the number of parameters. This is thanks to a built-in arguments array within each function that returns all the parameters accepted by the function.

3. Functions are actually objects, each of which is an instance of a function type, with properties and methods. Therefore, the function name is actually a pointer to the function object.

4. Function declaration:

function sum (num1,num2) {      return num1+num2    }

Or

var sum=function(num1,num2) {      return num1+num2;          };

Or

var sum=New// not recommended

No overloads in 5.JavaScript

 funtion Add (num) { return  num + 100< Span style= "color: #000000;" >; } funtion Add (num) { return  num + 200;} var  result=add (100); // 300  //  Think of the function name as a pointer, this example declares two functions of the same name, and the latter overwrites the preceding function, which is equivalent to  funtion Add (num) { return  num + 100; } Add (num) { return  num + 200 var  result=add (100); // 300  

6.this refers to the scope at which the function executes.

7. Each function contains: length and prototype. The Length property represents the number of arguments the function expects to receive.

function Sayname (name) {     function  sum (num1,num2) {     return num1+num2;} Funtion Sayhi () {     alert ("HI");} alert (sayname.length); //  alert (sum.length);    //  alert (Sayhi (). length); // 0

Reference:

Http://www.cnblogs.com/zxj159/archive/2013/05/17/3084579.html

3. Function functions

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.