views:

48

answers:

2
function doIt(param) {
   var localVar = param;
   //do lots of stuff with localVar
}

function doIt(param) {
   //do lots of stuff with param
}

Is there any difference in terms of efficiency between the code above?

A: 

param variable is already a local variable so the only difference between those two code snippets is that the first one creates useless copy of param variable.

Crozin
Not even that. Any decent compiler should get rid of the intermediate dead variables (like param).
Karmastan
+1  A: 

There is no difference. A parameter is just a local variable which is initialized with the passed argument at invokation time.

However, if you are going to change the value of your variable, it is often considered a good practice to leave parameter variables unaltered, simply for readability and maintainability reasons.

Daniel Vassallo