问题 1
Explain the concept of closures in JavaScript.
Closures allow a function to access variables from its outer (enclosing) scope even after the outer function has finished executing. They help in creating private variables and methods.
Example:
```javascript
function outer() {
let x = 10;
function inner() {
console.log(x);
}
return inner;
}
const closureExample = outer();
closureExample(); // Outputs 10
```
保存以便复习
保存以便复习
收藏此条目、标记为困难题,或将其加入复习集合。
这有帮助吗?
添加评论
查看评论