Posts

Showing posts from March, 2018

Closures: Behind the Scenes!

Image
Welcome! Hi, Welcome! We will discuss a very interesting concept related to functions,  “Closures” , what they are and how to use them. Let’s get started! First of all, what is a Closure? The concept might be a little bit abstract at first, so let’s jump to a concrete example: What does a Closure look like? Here you can see the general structure of a Closure: We have an enclosing function ( returnMultiplyFunction ) with a nested function ( multiplyBy ). The nested function uses a variable that is part of the enclosing function’s scope (in this case,  multiplyBy  uses x, the parameter passed to the outer function) The inner function is returned by the enclosing function. NOTE:  A Nested function is a function defined inside another function. You may ask, what happens when we call  multiplyBy ? We have two variables but we only pass in one argument,  y . What value will  x  have? Let’s find out! : ) Ready...