Question
Override JavaScript default parameter with undefined
I have a function with argument bar
that has a default parameter, ""
. How do I override bar
's default parameter with value undefined
?
const foo = (bar = "") => {
console.log(bar)
}
foo(null) // null
foo(undefined) // "" <-- I want this to log `undefined`
If this is impossible with default parameters, what would be an appropriate way to write foo
to achieve this?