Override JavaScript default parameter with undefined

what would be an appropriate way to write foo to achieve this?

If you mean to default only when there is no parameter passed to the function call, then you need to check the arguments length, or to spread the arguments if you want to keep an arrow function.

const foo = (...args) => {
  const bar = args.length ? args[0] : "";
  console.log(bar)
}

foo(null) // null
foo(undefined) // undefined
foo(); // ""

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)