Java Basics functions in JavaScript (Web knowledge)

Source: Internet
Author: User

1. In JavaScript, the format of the function
 function name (formal parameter list) {    functional body;}
2. JavaScript, the function needs to pay attention to the details

1. In JavaScript, when a function defines a parameter, it is not possible to declare a variable using the var keyword.
2. In JavaScript, there is no return value type, and if the function needs to be returned to the caller, it returns directly (return) and does not return if it does not need to be returned.
3. In JavaScript, there is no overloaded concept, and the function defined later overrides the function defined earlier.
4. In JavaScript, an object of arguments (array) is implicitly maintained inside any function, passing the value of the function to the arguments object and then assigning the data to the parameter by the arguments object.

3. Example
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8">5 <title>Exercises for functions in JavaScript</title>6 </Head>7 <Scripttype= "Text/javascript">8     //Requirement: Define a function to do the addition operation9     functionAdd (A, b) {Ten         varC=a+b; One document.write (c+"<br/>");//return Value: 33//After opening the following function, there is no output value, it has been overwritten by the following function A         returnC; -     }  -     //var d=add (11,22,13,34,14,15); the     //document.write (d+ "<br/>");//return value: -      - Add ( One, A, -, the, -, the) -     functionAdd (a,b,c) { +         varD=a+b+C; - document.write (d+"<br/>");//return Value: + document.write (arguments.length);//return Value: 6//Get internally maintained array arguments (array) length A     } at </Script> - <Body> - </Body> - </HTML>

Example result diagram

      

Original Dshore

Author's homepage:http://www.cnblogs.com/dshore123/

Source:https://www.cnblogs.com/dshore123/p/9447785.html

Welcome reprint, reprint must explain the source. ( If this article is helpful to you, you can click on the lower right corner of the recommendation , or comments, thank you!) )

Java Basics functions in JavaScript (Web knowledge)

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.