Before we can understand what a closure is, we must first understand nested functions and non-local variables. Nested functions in…