Posts

Showing posts with the label hoisting

JavaScript Buzzwords: Closures, Hoisting, Currying, Event Loop, Bind/Call/Apply

Image
1.     Closures JS by itself is not a language that is OOPS friendly. In order to mock the Abstraction/Encapsulation in the traditional OOPS, closures are used. A closure is just a pattern of writing a function (here function is treated as a “class”) Without Closures: No matter how many times you call CounterTest(), the  count  value is always “generated” fresh and hence  count   always increments from 0 and returns 1. But, what if you had to preserve the count value and on each call, it had to increment based on the previous result. Ex:  Closure to the rescue!   With Closures: Summarizing: ·          Child function has access to parent function’s private variables. ·          Parent function returns the child function and only exposes this to the outside world (Abstraction/Encapsulation) ·          Outside functions ar...