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
    • 190
    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:

    1. "use strict";
    2.  
    3. function add10(variable1) {
    4.  
    5. var variable1 = 20;
    6.  
    7. }
    8.  
    9.  

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

    1. "use strict";
    2.  
    3. function add10(variable1) {
    4.  
    5. variable1 = 20;
    6.  
    7. }

     

 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
Reset Password
Fill out the form below and reset your password: