Use of function functions

Source: Internet
Author: User

The composition of the function

function+ function name (parameter 1, parameter 2) {

function implementation;

}

The function name cannot be the beginning of a number, it can be a letter and an underscore;

function invocation: function name ();

Scope

Variables defined outside the function, called global variables, can be accessed throughout the document.

Variables defined inside a function are local variables and can only be accessed inside the function.

var a=10;

function aa () {

var a=20;

alert (a);

}

alert (a);

AA ()


A function is a data type that can be assigned to a variable

var f=function (b) {

return (B=B+1);

};

Alert (f (5));

Use f (parameter) when invoking

function can access functions inside itself

Function B () {

var a=5;

function bb () {

alert (a);

}

BB ();

}

b ();

Call function to use the return+ function when the intrinsic function has a return value

Function C () {

var a=10;

function bb () {

return a*2;

}

return BB ();

}

Alert (c ())

A function's call to its own intrinsic function

Function d (A, b) {

function DD (a) {

Return a+2

}

Return C=dd (a) +dd (b);

}

Alert (d (2,3))

function calls to other functions

function Add (A, b) {

return a+b;

}

function Sub (A, b) {

return a-B;

}

function bb (x,a,b) {

return x (A, b);

}
Alert (BB (sub,2,3))

Recursion of functions

function cc (a) {

if (a==1) {

return A;

}else{

Return A*CC (--A);

}

}

Alert (CC (4));

Use of 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.