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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With