Javascript learning notes (4) function part _ basic knowledge

Source: Internet
Author: User
This article describes how to call a function, how to return a function, how to create an anonymous function, how to create a dynamic function in javascript, how to call a callback function, how to distinguish between a method and a function, how to create a js global function, and how to use a function., prototype attributes, high-level functions, it is very practical. for reference, the function is event-driven or reusable code block executed when it is called.
Jscript supports two types of functions: one is internal functions (such as eval (), and the other is self-created.

The variable declared inside the JavaScript function (using var) is a local variable, so it can only be accessed inside the function. (The scope of this variable is local ).

You can use local variables with the same name in different functions, because only functions that have declared the variable can recognize the variable.

Function call Method

1. Common call: functionName (actual parameter ...)

2. Call the function by pointing to the function variable:

Var myVar = function name;

MyVar (actual parameter ...);

Return Function

1. When the function does not return a specific value, the returned value is "undefined ".

2. When a function returns a value, the return value is returned.

We can use the return statement to return the function to the place where it is called.

When the return statement is used, the function stops execution and returns the specified value.

A function usually returns a unique value, which may be another function:

The Code is as follows:


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.