JavaScript Programming Start (Seventh lesson) _ Basics

Source: Internet
Author: User
Chinese New Year has been relatively busy, let everyone down.
Learn the function today, although the statement has not finished.

Functions are a very important part of the JavaScript language, but they are also complex.
Here's a look at JavaScript functions.
functions are function plus function names and a pair with parameter brackets, and curly braces, where the braces are
The principal JavaScript statement.
Cases:
function Hanshuname (JS)//hanshuname is the name of the function.
{
document.write (JS, "<br>"); is the principal statement of the function.
}
Functions can be nested as follows:
function Qiantao (a,b) {
function Lqiantao (x) {return x*x}
Return Math.sqrt (Lqiantao (a) +lqiantao (b));
}
Functions can also be applied as data, so functions such as assignment, storage, delivery, and so on, can be handled like other data.
Cases:
function Zhi (x) {return x*x}
In fact, the function name has no meaning, but only the variable name that holds the function.
A=zhi (6);//a Store is the number 36;
b=zhi;//now B and Zhi refer to the same function.
C=b (5);//c Store is the number 25.
In a function body, an identifier arguments always has a special meaning, which is a special property of the calling object that refers to the actual parameter object. This actual parameter object has a large number of useful properties. In addition, it also has the role of an array.
Although a JavaScript function is defined with a fixed parameter, the number of arguments passed to it can be arbitrary when the function is invoked, and the array arguments[] allows full access to those actual parameter values. In addition, arguments has a length attribute, see the following example:
function Zhi (x,y,z)
{
if (Arguments.length!=3) {
Alert ("function Zhi called with" +arguments.length+ "Arguments,but it expects 3 arguments.");
return null;
}
}
Array arguments[] Also developed an important possibility for JavaScript functions to write functions that can accept any number of actual parameters.
function Zhi ()
{
var m=number.negative_infinity;
Traverse all Parameters
Retrieves and remembers the largest one.
for (Var i=0;i<arguments.length;i++)
if (arguments>m) m=arguments;
Returns the maximum parameter value.
return m;
}
var Lazgest=zhi (1,10,100,2,3,1000,4,5,10000,6);
You can also use the arguments[] array to write a function.


Calling the JS function
<a href= "#" onclick= "functionname ()" >link text</a>
<a href= "Javascript:functionname ()" >link text</a>
Let's talk about this today, the next section continues to say 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.