What is closure in JavaScript with a real time example?
A function that can access its parent scope, even after the parent function has closed is called JavaScript closure.
const parentMethod = () => {
const title = 'Advanced JavaScript Questions';
const innerMethod = () => {
console.log(title);
}
innerMethod();
}
parentMethod();
In other words, a closure gives you access to an outer function's scope from an inner function.
BY Best Interview Question ON 24 Aug 2022