This story on HackerNoon has a decentralized backup on Sia.
Transaction ID: ectRvK4bQfX2L8PQ5xAmkuogZ2GoQWjyAXq5rXZIjSo
Cover

Closure in Ruby and Javascript

Written by @gursimranjit1196 | Published on 2019/12/8

TL;DR
The nested functions/variables continue to live even when the outer function has completed its execution is closure. The value of x1 is first increased to 101 and assigned back in x1 and then we print value. That’s what basically happens when we execute the m1[] second time. The value updates from 101 to 102 and print on the console. The same process goes like this for both Ruby and Javascript. It is the same for the this example as well that the value of. x1 binds in the. returned function from. js_func function and you can simply play around with it's value from outside the function.

[story continues]


Written by
@gursimranjit1196
Technical Writer on HackerNoon.

Topics and
tags
ruby|rails|closures|javascript
This story on HackerNoon has a decentralized backup on Sia.
Transaction ID: ectRvK4bQfX2L8PQ5xAmkuogZ2GoQWjyAXq5rXZIjSo