58

Master JavaScript: Call By Sharing, Parameter Passing

 5 years ago
source link: https://www.tuicool.com/articles/hit/uUfyyej
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
B7jYvaf.png!web

T here are so many misconceptions and debate on the internet about how JavaScript passes values to functions. Some people write JavaScript uses call-by-value for primitive values and uses call-by-reference for data types like arrays, objects, and functions.

But the answer lies in the fact that JavaScript uses call-by-value for all data-types. It uses call-by-value for Arrays and Objects but in what is called call-by-sharing or a copy of reference .

In this article, we will look into the memory model of JavaScript during its execution of functions to see and understand what really happens.

What will we gain from this article?We will have a deep knowledge of how JS passes parameters to functions. With this knowledge, we can write a highly optimized JavaScript code.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK