Closure in Ruby and Javascriptby@gursimranjit1196

Closure in Ruby and Javascript

tldt arrow
Read on Terminal Reader🖨️
JS🚫

Too Long; Didn't Read

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.
featured image - Closure in Ruby and Javascript
Gursimranjit Singh Channa HackerNoon profile picture

@gursimranjit1196

Gursimranjit Singh Channa
react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!
Hackernoon hq - po box 2206, edwards, colorado 81632, usa