No. The curly brace pair of { and } characters on the left hand of a destructuring assignment is a syntax mechanism to tell the compiler to expect a object on the right hand side of the = sign. It is not the same syntax as used to create a new object. In the case of the example shown
const {a, b} = someObject;
in long winded terms is telling the compiler to create two constant variables a and b and assign them values of the same named properties of the object on the right hand side of the assignment statement. More briefly it's telling the compiler to produce the code equivalent of the older syntax version:
const a = someObject.a;
const b = someObject.b;
Destructuring an Array object is similar in that the [ and ] characters on the LHS aren't defining an array but are telling the compiler to expect an iterable object on the RHS of the assignment. For example
const [a, b] = someArray;
is telling the compiler to generate code equivalent to
const a = someArray[0];
const b = someArray[1];
Note destructuring an iterable object (typically an Array object) in conjunction with using a rest operator (...) on the LHS of the assignment, will require creating a symbol iterator to inspect properties in sequence at run time. Thanks to @VLAZ for the pseudo code:
const _temp = someArray[Symbol.iterator]();
const a = _temp.next().value
const b = _temp.next().value
If the compiler generates this code for the JS engine to run, then the iterator held in _temp would need to be GC'ed afterwards. However it may be worth remembering that the ECMAScript specification of JavaScript is devoid of implementation details and if the JS engine were to call native code for some or all of the steps needed to implement rest operands then maybe requisite temporaries might not be on the heap and in need of GC later.
For context an example of JS array destructuring with a rest operator:
const someArray = [0,1,2,3];
let [a, b, ...c] = someArray; // as a change from const variables
console.log(`a = ${a}, b = ${b}, c = [${c}]`);
TL:DR:
- The braces on the LHS of a destructuring assignment are syntactical to determine if an object (curly braces), or an iterable object or string ("[]" braces, is on the RHS of the assignment operator.
- Destructuring syntax does not itself imply a temporary object, plain or Array, needs to be created.
- Use of a rest operator (...) when destructuring an iterable on the RHS implies the need to create an iterator object at run time. It is not specified whether such iterator would used in native or JS code, or whether it would reside on the heap or call stack. Subsequent garbage collection of its memory may or may not be required depending on JS engine implementation.
- Use of a rest operator when destructuring an ordinary object, if implemented in run time JavaScript is likely to call
Object.keys or Object.entries to collect properties of the object that weren't assigned to variables. Such run time calls would create return values that would need to be GC'd after the rest operator completes. Again it all depends on how the JS engine implements the rest operator.
- The consensus is that trying to optimize array or object destructuring is unlikely to be worthwhile.
const a = target.sub.a, b = target.sub.b;is optimized toconst temp = target.sub, a = temp.a, b = temp.b;