Closure: a function that has access to a variable in the scope of another function. Code examples:

function closure1() {
    let a = 1;

    function closure2() {
        console.log(a);
    }
    closure2();
}

closure1();
Copy the code

Print result:

1
Copy the code

In the code above, the scope of the function Closure2 accesses the local variables in Closure1. The closure is then generated in Closure1, which closure1 calls the closure function.

For example, if A and B are neighbors, A can go to B’s house to get some shampoo and shower gel.