Parameters of JavaScript functions (formal parameters/actual parameters)

function parameters

Formal parameters :
the parameters in parentheses at the time of definition : the parameters in parentheses at the time of calling

function add(a,b){
    
    
	var num=a+b;
	return num;
}
var x=add(1,2);		//3
var y=add(1,2,3);	//实参>形参 3
var z=add(1);		//实参<形参 NaN
arguments group of actual parameters

The arguments are not an array, but an array-like concept (with array characteristics, but not with array methods)

function add(a,b){
    
    
	console.log(a);	//a
	console.log(b);	//b
	console.log(argument[2]);	//c
}
add(a,b,c);
array base slot method Index attribute length
array have have
arguments none have

Guess you like

Origin blog.csdn.net/weixin_68915174/article/details/128374735
Recommended