0

When extracting a variable from an object, is there a way to already check there if it's undefined and set a default? I'm basically trying to achieve the below code in one line:

let { name } = user
name ??= "John"
bler
  • 63
  • 1
  • 6

1 Answers1

0
let { name = "John" } = user;

(destructuring on MDN)

Toastrackenigma
  • 7,604
  • 4
  • 45
  • 55