Javascript
100 Front End Interview Questions Challenge

Pass By Value & Pass By Reference

Outline

Pass by Value is to copy data from an existing variable into a new one. Changes made to the new variable will not be reflected in the first.

Pass by Reference is to create a new variable that references an existing variable. The new variable is only a pointer to the old, and any changes made to either will reflect in both.

In JavaScript, all primitive data types will pass by value, while all complex data types will pass by reference.

If you want to duplicate a complex data type, there are a few ways to make sure your are passing by value and not by reference. One way is to create a new structure and pass into it all of the data from the other using the spread operator.

 

I finished! On to the next chapter