What's the difference between an argument and a parameter?

后端 未结 30 1902
北恋
北恋 2020-11-22 01:08

When verbally talking about methods, I\'m never sure whether to use the word argument or parameter or something else. Either way the other people know what

30条回答
  •  花落未央
    2020-11-22 01:46

    Parameters are variables that are used to store the data that's passed into a function for the function to use. Arguments are the actual data that's passed into a function when it is invoked:

    // x and y are parameters in this function declaration
    function add(x, y) {
      // function body
      var sum = x + y;
      return sum; // return statement
    }
    
    // 1 and 2 are passed into the function as arguments
    var sum = add(1, 2);
    

提交回复
热议问题