What is closure In basic terms, the nested functions/variables continue to live even when the outer function has completed its execution is closure. Lets have an example for both Ruby and Javascript Ruby x1 = proc{ x1 = x1 + ; puts x1 } puts x1 m1 = ruby_m m1[] m1[] m1[] . . . def ruby_m 100 1 end # NameError: undefined local variable or method `x1' # 101 # 102 # 103 You can see that the variable x1 binds in the block and you can play around the variable’s value even from outside the method. Brief Description: First we store the (return statement of ) in . The basically contains the scope of in it. proc ruby_m m1 proc x1 Then when we try to execute the from outside the method, and the value of is first increased to 101 and assigned back in and then we print value. proc x1 x1 Now in the block, the value of is updated to 101 i.e now when you execute the , you can see the value of x1 as 101. That’s what basically happens when we execute the m1[] second time. The value updates from 101 to 102 and print on the console. proc x1 proc And the same process goes like this. Javascript { x1 = { x1 = x1 + .log(x1) } } func1 = js_func() func1() func1() func1() . . . ( ) function js_func let 100 return ( ) function 1 console // 101 // 102 // 103 The explanation is 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. Thanks for reading. :)