paint-brush
Closure in Ruby and Javascriptby@gursimranjit1196
239 reads

Closure in Ruby and Javascript

by Gursimranjit Singh Channa2mDecember 8th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

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
Gursimranjit Singh Channa

Gursimranjit Singh Channa

@gursimranjit1196

L O A D I N G
. . . comments & more!

About Author

Gursimranjit Singh Channa HackerNoon profile picture
Gursimranjit Singh Channa@gursimranjit1196

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Learnrepo