Javascript closure

What is closure in javascript and it is application

It’s just a concept. You can think of a closure as the function that is assigned (or returned as a value) and its associated scope.

Applications :-

  • Javascript closures can be used to implement throttle and debounce functionality in your application.
  • To allow others to access values you have inside your function, without letting them directly modify the variables.
  • The anonymous function is passed as a value to the setTimeout function, thus, creating a new closure and associating the variables in the scope associated to that new function.
1 Like