First, let's look at how values are passed, copied, and stored in memory by JavaScript.
In JavaScript, there are two types of Values.
This is the data that has a single value and no additional methods or properties. E.g. String, Number, Boolean, Undefined, and Null. These data types are passed by value.
2. Reference Values
All Objects in JavaScript are reference types. E.g. Objects, Arrays, Classes, etc. These data types are passed by reference.
When we assign a primitive value to a variable, the actual data is stored in a memory called the “STACK” and the variable holds…