argument is a special parameter of a function in javascript. For example, the following is used to access the function parameters and determine whether the function is executed.
The code copy is as follows:
<script type="text/javascript">
function saysHello () {
if (arguments[0] == "bye")
return;
else
alert( "hello" + arguments[0]);
}
</script>
Use the length attribute of argument to return the number of parameters.
The code copy is as follows:
<script type="text/javascript">
function cNumbArg () {
return arguments.length;
}
document.write(cNumbArg(25,2255,"Hello")+"<br>");//Return 3
document.write(cNumbArg()+"<br>");//0
document.write(cNumbArg(1111)+"<br>");//1
</script>
Use argument object to simulate and reload functions
The code copy is as follows:
<script type="text/javascript">
function fnAdd () {
if (arguments.length == 0)
return;
else if (arguments.length == 1)
return arguments[0] + 5;
else (arguments.length >1 )
var iSum =0
for(var i=0;i< arguments.length;i++)
iSum += arguments[i];
return iSum;
}
document.write(fnAdd(5)+"<br>");
document.write(fnAdd(10)+"<br>");
document.write(fnAdd(10,20)+"<br>");
document.write(fnAdd(10,20,30,40)+"<br>");
</script>
Have you got a new understanding of argument? In fact, he can do more things. Children's shoes think about it and try it more.