Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • TypeError: variable "x" redeclares argument in javascript

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 162
    Comment on it

    If you redeclared a function parameter in the function block using a var. This is a naming conflict and javascript gives you a warning "TypeError: variable "x" redeclares argument"

    This warning occurs in strict mode only. In non strict mode javascript ignores the error.

    The below code will produce the error:

    "use strict";
    
    function add10(variable1) { 
    
      var variable1 = 20;
    
    }
    
    

    To fix this warning, var can be ignore, because the variable is already in existence. You may also rename the variable to 'variable2'.

    "use strict";
    
    function add10(variable1) { 
    
      variable1 = 20;
    
    }

     

 1 Comment(s)

  • Hello you can declare this variable at call the above function otherwise pass in call this function for example
    <script>
    $("#btnsubmit").on("click",function(){
     variable1=" ";
    add10(variable1)
    });
    function add10(variable1)
    {
    //your code
    }
    </script>
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: