It is best to simply pass an object containing all the parameters:
function myFunction(parameters){ if(parameters.a) { //do something } if(parameters.b) { //do something } }
Then you can call the function as follows:
myFunction({b: someValue});
If you want to be able to pass falsy values as parameters, you will have to change if a bit:
if(parameters && parameters.hasOwnProperty('a')){ //do something }
Another option is to simply pass null (or any other falsy value) for parameters you don't want to use
helo(null, parameterB);
source share