Passing by Value vs Passing by Reference in JavaScript

A thing that I’ve heard desktop application developers say about web developers is that web developers don’t know what phrases passing by value and passing by reference mean. I’m sure most of us, web developers, know what those mean. If you don’t, you should learn them ASAP!

To recap, passing by value means that the value that you pass to a function gets cloned and independent, and that changes to that value made within the function are not reflected on the original value. On the other hand, passing by reference means that the object passed to a function is linked to the one that is passed, so the original is affected by any changes that happen in the function.

I’ve done some testing to see when the values are passed by value, and when they are passed by reference in JavaScript, and here’s what I’ve found out.

[ read more... >

Comments