It works:
const { foo, bar } = someFunc();
So:
let { foo, bar } = someFunc();
But if I try to destroy the already declared variables ...
let foo = 0; let bar = 0; { foo, bar } = someFunc();
then:
Uncaught SyntaxError: Unexpected token =
Is it for design? Is there a workaround other than declaring a temp object to get the value? I do this in a switch / case statement; foo and bar are declared on top and used after the switch. So far I can only do:
const temp = someFunc(); foo = temp.foo; bar = temp.bar;
source share