Skip to content Skip to sidebar Skip to footer

Call Stack Variables In Javascript

I read somewhere that whenever a function gets called, the compiler puts all the visible variables on a stack, somewhat related to closures as well, now with the following code I'm

Solution 1:

Yes a closure will be created by the anonymous function you pass to then. The variable which is being closed over is the body value being passed in to the outer list function.

Each time you call list - in the above example you've called it twice - you are adding some values to the body object and then instantiating a new closure and making that value available for it. The values that you're passing to each call of list are both object literals which means they're completely separate and you will be handing different values to the closure so there is no way the call involving 'coke' will ever have a connection to the call involving 'pepsi'.

Post a Comment for "Call Stack Variables In Javascript"