Copy by value of a composite data type in javascript

Vamsi K
Nov 8, 2020

Before getting into the topic let us understand what is a composite data type.

Composite Data Types:

As the name suggests composite data types can hold collections of different data types.

Objects, Array, and Functions (which are eventually objects) are composite data types.

Variables that are assigned to these composite data types are given a reference to the data of that respective data type, that reference points to its(composite data type) location in memory.

Now let us look at how to perform copy by value of these composite data types.

Copy by value of composite data type:

Spread syntax (...) allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.

Let us understand the usage of spread operator by the below example:

using spread operator to perform call by value

Clearly, we can see that the value of a is successfully copied to b using the spread operator.

--

--