Skip to main content
Post Closed as "Needs details or clarity" by Andy, Roman Pokrovskij, Patrick, lmiguelvargasf, Vickel
Source Link
xx yy
  • 634
  • 1
  • 8
  • 17

conditionally deconstruct object (javascript)

I want to check an argument, if it was undefined (or false), I will assign a value to it by deconstructing an object

function test(x){
  let obj={x:1,y:2}
  if(!x){x}=obj;
}

note: I don't want to use a temporary variable

if(!x){
  let {temp}=obj;
  x=temp
}