I have a question for using optional arguments in function. Here is an example:
function add (num1=2,num2=3){
return num1+num2
}
console.log(add(4,2)) // 6
console.log(add(5)) // 8
console.log(add()) //5
This work correct, but what if I want to pass only num2
as argument without num1
like this:
console.log(add(6))
Here this argument will be num2
not num1
which will return 8
- i don't want to use object as argument
i don't want to pass undefined as first argument like this:
console.log(add(undefined,5))
i want to achieve like express.js :
How can I do this. Any help.