Detailed explanation of JavaScript function parameters _javascript techniques

Source: Internet
Author: User

JavaScript functions can be invoked with any number of arguments without specifying a few parameters when the function is defined. Because a function is weakly typed, there is no way to declare the type of argument it expects, and it is legal to pass any type of value to any function.

The 1.Js function can pass in different parameters, such as

function writenstring (STRMSG) {
document.write (strMsg + "<br>");
}

2.Js function return value, the JS function can return the results of the run, the function can be regarded as a black box, using the parameter input data to produce the desired results, such as

function one2n (intnumber) {
var inttotal = 0;
for (Var i=0;i<=intnumber;i++) {
 inttotal +=i;}
return inttotal;
}

3.Js function's transfer value and address parameter

Pass value: Just pass the value of the variable into the function, the function will configure the memory to save the parameter value, so does not change the value of the original variable.

Pass: The memory location where the variable is actually saved is passed into the function, so if you change the value of the parameter in the function, the value of the original parameter is also changed.

Numbers, strings, and Boolean------values

objects, arrays, and functions----address

String Object--Address

An array of parameters for the 4.Js function

JS functions have a parameter array (Arguments array) object, called the Arguments object. When you call a function to pass in a parameter, the function can use the object of the parameter array to get the number of parameters and individual parameter values, even if the parameter names are not specified.

function Suminteger () {
 var total = 0;
 For (Var i=0. i<suminteger.arguments.length;i++) {Total
  + = Suminteger.arguments[i];
  }
  return total;
}
Call function
inntotal = Suminteger (100,45,567,234);
document.write ("function Suminteger (100,45,567,234):" +inttotal+ "<br>");

Variable range of 5.JS function

The JS function has two kinds of variables:

A variable declared within a function by a local variable, which can only be used within a program line within a function, and the program code outside the function cannot access the variable. \ Variables

Global Variables variables declared outside functions, the entire JS program's functions and program code can access this variable.

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.