In JavaScript, a closure is created when a function is defined inside another function, and the inner function has access to the variables of the outer function.
This allows the inner function to "close over" or encapsulate the outer function's variables.
Closures are a powerful and important concept in JavaScript, and they are commonly used to create private variables, handle asynchronous code, and more.
// Neel.B
const clouserFunction = () => {
let data = "Hello Neel"
return () => {
return `${data} how r u?`
}
}
const closureInit = clouserFunction()
const closureData = closureInit()
console.log(closureData)
//output : Hello Neel how r u?
© www.thecoderjob.com. All Rights Reserved. Designed by HTML Codex