Today #Day126 of #365DaysOfCode, Learning Essential JavaScript Interview Questions.
console.log((function f(n){return ((n > 1) ? n * f(n-1) : n)})(10));10! = 36,28,800
console.log(
(function f(n) {
return n > 1 ? n * f(n - 1) : n;
})(10)
);(function(x) {
return (function(y) {
console.log(x);
})(2)
})(1);output: 1
In JavaScript, a closure is implemented as an “inner function”; i.e., a function defined within the body of another function.
An important feature of closures is that an inner function still has access to the outer function’s variables.
Learned and practiced Essential JavaScript Interview Questions involving topics like function recursion and JS closure.
