JavaScript, how to pass in data from the stack to the heap

One way to pass data from the stack to the heap is as an argument in a function call.

How to pass in data from stack to heap
In JavaScript, primitive data from a variable can be passed into a function as a copy, via a function argument which is given to a function parameter.

The parameter acts as the interface between stack and heap. In other words, the data in the variable and the data being passed into the function becomes independent of each other.

So even though a function resides in the heap, we are not pointing or passing by reference, we are actually cloning the data to be processed by the function, which is the same as passing by value (remember? like copying data into another variable or “adding”value).

If this intermediate level JavaScript subject interests you, I go into deeper detail on my eBook:

Advertisements

Author: tarau

technical writer, web technologies

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s