The function is initially

Source: Internet
Author: User

I. Definition of functions
1. Functions are divided into named functions
function FuncName ()
Where FuncName ' is the name of the function and can be called by funcname (), you can use function to get its address.

2. Anonymous functions
var funcName = function () {}
The right side is the direct volume, and the left is the variable. The equivalent of assigning a direct amount to a variable. Can be called by funcname ().
Two. How to use
1. Direct use
function FuncName () {
Console info ();
}
FuncName ();
You can do it yong
FuncName ();
function FuncName () {
Console info ();
}
2. Assigning values to use
function FuncName () {

}
var temp = FuncName;
Temp ();
Three. Scope
1. General variable Scope
JS has no block-level scope, but has a function scope: A variable in a function that has meaning within the function to invoke
2. Reference scopes for functions
function can not be used outside, the outside cannot use the inside.
Four. Transfer of parameters
1. Parameter list
var num1 = 1,num2 = 2;
function FuncName (3,4) {
Console info (3);
Console info (4);
}
FuncName (num1,num2;)
2. Participate in the actual parameter
Outside of the function is the argument, which passes the formal parameter.
Five. Return value
Return can be used as a closing sentence for a function, as long as you encounter a return so that the nearest function stops and returns a value

The function is initially

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.