JavaScript arguments, formal parameters, and variables

(1) What is a formal parameter and what is an actual parameter in a js function, and what is the difference between the two?
Parameters are also called parameters. In js, the variables received by functions are divided into formal parameters and actual parameters. The actual parameter refers to the specific data that actually participates in the js function call. A formal parameter is a variable that receives the actual parameter value when the function is called. According to actual needs, formal parameters are optional. When there are no formal parameters, the parentheses cannot be omitted. When there are multiple parameters, the parameters are separated by commas.
 
Example:
window.onload=function()
{
function compare(a,b)
{
return(a>b?a:b)
}
alert(compare(5,9));
}
In the function compare(), a and b are formal parameters, and the 5 and 9 entered by the alert function in calling compare() are actual parameters.
 
 
(2) What is the difference between variables and parameters in js?
 
A variable is a variable whose value is allowed to change while the program is running. A constant is a quantity whose value is not allowed to change while the program is running. js variables are declared using the keyword var.
 
Variable instance:
var i,sum;
//declare variables i, sum
 
The parameters in js are only for function calls, and the parameters are the supplementary components of the function.
 
 
(3) What is an object in javaScript?
 
Object is the basic data type of javascript, an object is a kind of conform value: it aggregates a lot of values, which can be accessed by these names.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324607561&siteId=291194637