Hi Dev Community π
Did you know that we can actually set our function parameter with a default value, It will make your function at least return default value instead of undefined
, sound great isn't it π€©
function multiply(a=1 ,b = 1) { return a * b; } console.warn(multiply(3,2)) // expected output : 6 (3 multiply by 2) console.warn(multiply(5)) // expected output: 5 ( 5 multiply by 1) console.warn(multiply()) // expected output: 1 (1 multiply by 1)
now could you predict the expected output from this function π€
function substraction(a=1 ,b = 3) { return a - b; } console.warn(substraction(3)) // the result is ?
Top comments (0)