Search code examples
javascriptjqueryperformancelistenerdraggable

does it slow performance to declare parameters in a javascript function if they are not being used


I am using a plugin which monitors the dragging of an element. As the coordinates of the element change when it is dragged, several parameters are made available to an event listener function:

$el.on('dragMove',onDragMove);

onDragMove = function(e,pointer,vector){
  //
}

Is there any performance benefit to removing those parameters if I am not using them within the function:

onDragMove = function(){
  //
}

?


Solution

  • There is minimal impact on performance due the low memory consumption of declaring the arguments as variables, since the Javascript plugin you are using is still sending to the arguments at those positions. Ultimately it would depend on the received data, as the function arguments, other than objects, are passed by value and not by reference.

    The biggest benefit to removing the declarations, would be more so for readability of your code.