Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redeclaring function parameters as variables?

I can't seem to find an answer for this anywhere on the 'Net...

Is there any reason, advantage, or disadvantage to redeclaring function parameters as local variables?

Example:

function(param1, param2) {
  var param1, param2;
  ...etc...
}

Seems extremely redundant to me, but maybe I'm missing something...?

Thanks,

Brian

like image 548
DondeEstaMiCulo Avatar asked Jan 23 '23 16:01

DondeEstaMiCulo


2 Answers

If the names of the declared variables are the same as the ones as the function parameters then it does absolutely nothing. Completely worthless. Doesn't even change the value of the variable.

like image 151
Thomas Eding Avatar answered Jan 25 '23 07:01

Thomas Eding


There is no good reason to ever redeclare a local variable with the same name as a parameter. Most languages wouldn't allow this, but JavaScript allows pretty much everything.

like image 27
Samuel Neff Avatar answered Jan 25 '23 05:01

Samuel Neff