JavaScript Basic Series (vii) function (definition and allocation function)

Source: Internet
Author: User

A function is a statement that can be run at any time, simply by saying that a function is a set of statements that completes a function that accepts 0 or more parameters.

The basic syntax for a function is as follows

function function Name ([arg0,arg1,...... ArgN]) {statement[return[expression]]}

where function is the keyword of the custom functions, functionname is the function name, ARG represents the various parameter lists passed to the function, and the parameters are separated by commas. The parameter can be empty.

Statement is a function of the province, can be a variety of legitimate code blocks.

Reture expression is the value of the return function expression, which is also optional. A simple example is shown below.

    function Sayname (yname) {   document.write ("Hello" + yname)    }   sayname (112);

In addition, JavaScript does not execute after Rerurn.

<div id= "xxx" style= "width:200px;height:100px;background-color:aquamarine" ></div><script type= " Text/javascript ">    function  cnumber (InNmuber1, inNumber2) {        return InNmuber1 + inNumber2    =  cnumber (40,20);    document.getElementById ("xxx"). InnerHTML = Irese; </script>

There may be multiple return in a function

<div id= "xxx" style= "Width:200px;height:100px;background-color:aquamarine" ></div>
<script type= "Text/javascript" > function cnumber (InNmuber1, inNumber2) { if (inNmuber1 >= inNumber2) return inNmuber1- inNumber2 Else return inNumber2- inNmuber1 = cnumber (10,20); document.getElementById ("xxx"). InnerHTML = Irese; </script>

JavaScript Basic Series (vii) function (definition and allocation function)

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.