If I have a function with two different parameters, how can I make it so that if I input only one parameter, it will use the input as the second parameter rather than the first parameter? For example, if I have this function:
function x(a=1,b=2) {
console.log(a);
console.log(b);
}
and call x(3)
, it will use the 3 for a
and return "3, 2"
x(3);
=> 3
2
I want it so that the function instead uses the 3 for the b
parameter, and therefore returns "1, 3"
x(3);
=> 1
3