If you have any query feel free to chat us!
Happy Coding! Happy Learning!
A function defined inside another function is called a nested function or an inner function.
Inner functions have access to the variables and parameters of the outer function. This is called "lexical scoping" or "closure". The inner function can use these variables even after the outer function has returned.
Here's an example:
javascriptCopy code
function outerFunction(x) { function innerFunction(y) { return x + y; } return innerFunction; } var newFunction = outerFunction(4); console.log(newFunction(3)); // Output: 7
In this example, outerFunction
returns innerFunction
, and assigns it to newFunction
. When newFunction
is invoked with an argument of 3
, it returns the sum of x
(which is 4
) and y
(which is 3
), resulting in 7
.
Note that x
is defined in outerFunction
, but innerFunction
has access to it due to closure.
Comments: 2
I am not able to access videos from second class and further. I have already completed first class
When will I get my course?
Now, Your query was resolved.