We all know that JS inside the parameters of the transfer can be different, for example, we have a function:
< script type = "Text/javascript" > function one (a,b,c) { this .x = A; Console.log (a); } One ( 1 ); </ script >
The number we passed was only one 1, but the formal parameter had ABC three. That's not right, is it?
This time if we look at B,c, it will show undefined. PS: for example Console.log (b).
Of course, there would have been no such two numbers. How can I get it for you?
In the face of such arguments and formal parameters of the case, JS is how to achieve it? Let's take a look at some code:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metahttp-equiv= "X-ua-compatible"content= "Ie=edge,chrome=1"><title>The difference between the formal parameter and the actual parameter of a function in JavaScript</title></Head><Body> <Scripttype= "Text/javascript"> functionOne (a,b,c) {returnone.length; } functionBoth (a,b,c,d,e,f,g) {returnarguments.length; } console.log (one ()); //3Console.log (both ());//0 </Script></Body></HTML>
Here we return the one.length in the one function and return the arguments.length in the function . As you may have found, the output of one () returns one.length as the number of formal parameters, and argument.length is the number of arguments.
Seconds to understand the wood there?
We can even use arguments[0] to take the number of arguments.
But why do the numbers without formal parameters be represented in an array-like way? All right, I know you're a Virgo, and everything you need is right. You can use this unless you have an array of parameters. Otherwise in the function we can only use the name of the formal parameter to obtain the actual parameters.
In the C#,java of the type and number of relative JS requirements are very strict, a little on the error. And JS because of this design and can become a relatively flexible language.
The above method is the realization that JS relies on the equal number of formal parameters and actual parameters. As for the type of the same, JS what type can be written as var a = ..., what is the type? So it is said that JS is a weak type of language!
How to implement the parameters and arguments of functions in JavaScript