Let say I have a JavaScript function and I want to use it as number to calculate.
However, I could either pass in string number (then convert to integer) or integer directly. Which one is good practice, considering that I’m writing plugging for other users to use and they have no knowledge of implementation detail (of course I could read function signature to see which one to pass in).
Thanks.
Handling all conversions within the function body allows for greater flexibility. A function is supposed to do stuff for you, not require you to do stuff.
Converting from string to integer isn’t difficult, and you could throw an exception if the string passed is unparseable to prevent silent failure.