A brief analysis of the difference between arguments and arguments.callee in Javascript

  • 2020-06-01 08:13:40
  • OfStack

To understand the specific difference between arguments and arguments.callee by using an example:

The code is as follows:

<script type="text/javascript">        
        function check(args){            
            var ac = args.length; 
            var ex = args.callee.length; 
            document.write("ac:" + ac + '<br>'); 
            document.write("ex:" + ex + '<br>'); 
            if (ac != ex) { 
                document.write("wrong number of arguments: expected: " + ex + "; actually passed" + ac + '<br>'); 
        function f(x, y, z) { 
            document.write(x + y + z); 

Call method:

<input name="wr" type="button" value=" call " onclick="f(1,2)" /> 

The result after operation is:

wrong number of arguments: expected: 3; actually passed2

My understanding:

arguments is the calling object, the object that calls this method
arguments.callee is the current object, which in effect returns the currently executing function object
And you can see that in this example
arguments actually means the function "f(1,2)"
argument.callee actually means "function f(x,y,z){}"

Related articles: