# Closed Bag
Closures are meant to be closed and wrapped up. In simple terms, a structure with a closed function and a package function. The so-called closures are,
There is a closed, non-public, parcel structure, or space.
In JS, functions can form closures. The general function is a closed structure of the code structure, that is, the characteristics of the package, and according to the scope rules,
Only allow the function to access external data, external access to the internal function of the data, that is, closed external non-public characteristics. Therefore, functions can form closures.
# # Closure to solve what problem
1. Closures do not allow outside access
2. The problem to be solved is to access the data indirectly
Functions can form closures, the problem is to access the data inside the function
```
function foo () {
var num = 123;
return num;
}
var res = foo ();
Console.log (RES); = 123
```
1. It is true that the data in the function is accessed
2. However, the data cannot be accessed for a second time. Because another call to Foo at the second visit means that there is a new num = 123 coming out.
The data within the function cannot be accessed directly outside of the function, so if a function is defined within the function, then the intrinsic function is directly accessible.
```
function foo () {
var num = Math.random ();
function func () {
return num;
}
return func;
}
var f = foo ();
F can access this num directly
var res1 = f ();
var res2 = f ();
```
What is a closure package?