Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Homonymous function parameters and private variables [closed]

When having to format or transform some function parameters in JavaScript, I usually create homonymous private variables (private variables with the same names as the function parameters):

function myFunction(param) {
  var param = Math.floor(param);
  // More code referencing param many times here...
}

Question: is that considered bad practice? Is there any drawback I should be concerned about?

like image 746
Ismael Ghalimi Avatar asked Oct 22 '22 18:10

Ismael Ghalimi


1 Answers

the var is ignored by the interpreter and this is not defining a second variable. So you might as well save you the time to type 4 extra chars :)

same thing as doing:

var var1 = 2;
var var1 = 3;
like image 61
Pascal Belloncle Avatar answered Oct 31 '22 15:10

Pascal Belloncle