Where would you use closure in realworld development Give an
Where would you use closure in real-world development? Give an example in a language that supports closures
Solution
Answer :
Closure :-
1) A closure is a persistent scope which holds on to local variables even after the code execution has moved out of that block. Languages which support closure (such as JavaScript, Swift and Ruby) will allow you to keep a reference to a scope (including its parent scopes), even after the block in which those variables were declared has finished executing.
2) The scope object, and all its local variables, are tied to the function, and will persist as long as that function persists.
Example :-
<script>
</script>
