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?
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?
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.
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.