Sort Javascript function learning notes _ javascript skills

Source: Internet
Author: User
Tags define function
Sort out the Javascript function learning notes. A series of previous articles are about the study of Javascript. This article is about the further study of Javascript Functions. I hope you will continue to pay attention to it. 1. What is a function?
If you need to use the same piece of code multiple times, you can encapsulate them into a function. A function is a set of statements that can be called in your code at any time. Each function is actually a short script.
For example, you need to complete the functions of multiple groups.

Var sum; sum = 3 + 2; alear (sum); sum = 7 + 8; alear (sum );

If you want to implement the sum of eight groups, you need 16 lines of code. The more you implement, the more lines of code. Therefore, we can put the code block that completes a specific function into a function and directly call this function to save the trouble of repeatedly inputting a large amount of code. Function completion:

Function add (a, B) {sum = a + B; // you only need to write it once.}; add2 (); add2 );...... // you only need to call the function.

2. define functions
Define function syntax

Function Name (parameter argument) {function body statements;} // function-Defined function keywords. You can use the function name as the function name, replace the "function body" with the code to complete a specific function.

Function shout () {var beatles = Array ("John", "Paul", "George", "Ringo"); for (var count = 0; count <beatles. length; count ++) {alert (beatles [count]) ;}// the loop statements in this function will pop up in sequence to display the content in beatles. Shout (); call the function to execute the action in the script

To sum two numbers and display the results:

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.