Basic description of JavaScript Functions and javascript Functions

Source: Internet
Author: User

Basic description of JavaScript Functions and javascript Functions

What is a function?

A function is a code segment that completes a function.

A function is a code segment that can be executed repeatedly.

Convenient function Management and Maintenance

Custom Functions

Use the function keyword

Function Name ([parameter,...]) {

Code segment;

Return value ;}

Note:

The function name must not contain special characters.

The function name should have a clear meaning

It is recommended that the function name follow the hump mark or underline method.

Function names are case sensitive

If the function name is repeated, overwriting is generated.

A function can have either a parameter or no parameter. Either a parameter or multiple parameters can exist.

The function adds the return value through return. If no return is returned, undefined is returned by default.

No function call or execution

Anonymous Functions

Function expressions can be stored in variables or used as a function.

Anonymous functions can be passed as parameters to other functions, and the receiver functions can complete some functions through the passed functions.

You can use anonymous functions to execute some one-time tasks.

Construct a Function through Function ()

Defined by built-in JavaScript Function Constructor (Function ()

var myFunction=new Function('a','b','return a+b');var myFunction=function(a,b){return a+b;};

Note:

The above two methods are equivalent.

Avoid using the new keyword whenever possible

Source code

<! DOCTYPE html> 

Running result:

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

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.