What should I pass in for existing function arguments that have no value, undefined or null, after I add more parameters to the function?
Existing function foo(a, b) is called like foo(1) and foo(23, "hi"). After adding a new parameter, it's foo(a, b, c) and I want to change foo(1) to be foo(1, undefined, 3.2) or foo(1, null, 3.2).
Does null 'looking better' override the concern that existing code may already expect the second param to be undefined in some cases?
Posted Jul 14, 2018, 4:47 AM UTC
Doesn't really matter. I usually try to stay away from using literal
undefinedthough, and usenullwhen I'm intentionally leaving something out (or aMaybeor something).If you have optional arguments like that, though, you may want to consider passing all of the arguments as a single object, and just leave off the unnecessary property.