What is the best way to redeclare a function parameter if it is not actually passed into the function?
function testVariable(foo, bar) {
bar = bar ? bar : foo; // <--
return bar;
};
const myFinalValue = testVariable("testValue");
I want to do this to ensure that bar has a value before I continue my automation (return, in this example).
Do I have to declare a new variable name or is it possible to overwrite the given parameter?
If I overwrite that parameter, will the overwritten variable become global if no value has been passed for that parameter into the function (per the example)?
Just use defaults, and then check if the variable is the default, if it is then do whatever you want
function testVariable(foo, bar = foo) {
return bar;
};
const myFinalValue = testVariable("testValue");
console.log(myFinalValue);