How to write to make use of closure features in callback functions

  question
function test1() {
 var a = 1;
 return function(){
 console.log(a);
 bracket
 bracket
 test1()();
 //1

In test1 function, A in the returned Anonymous function can be obtained, making use of the property of closure.

function test2(cb) {
 var a = 1;
 return cb
 bracket
 
 test2(function(){
 console.log(a);
 })();
 // a is not defined

However, it is rewritten into the test2 function, which shows that a has no definition by using the callback function. in this case, a can be obtained by simply passing a parameter into cb.

function test3(cb) {
 var a = 1;
 return cb(a)
 bracket
 
 test3(function(a){
 console.log(a);
 })
 // 1

However, this is not the use of closure features, I would like to ask how to write to use closure features in callback functions.

function test3(cb) {
 var a = 1;
 return cb()
 bracket
 
 
 function test4(){
 var a = 2;
 test3(function(){
 console.log(a);
 });
 bracket
 
 test4()
 //2

Well, it seems to say that I have a train of thought. Write the test4 function so that it is ok.
The reason is the context problem when Anonymous function was created. It was already created as a parameter instead of being created in the test3 function.
Parameter a is therefore 2 instead of 1.
Is this my correct explanation?

The subject is already standing at the door of the truth.

First of all, the conclusion is that the scope is in the functionBe createdFrom that moment on, it was confirmed, andNot calling. Imagine this scenario,

/* a common module */
 (function(){
 //Some local variables
 var a,
 b,
 c,
 d;
 
 function Foo(x, y, z){
 // todo
 /* use variables such as a,b,c */
 bracket
 
 window.Foo = Foo;
 })();

We wrote a global function Foo, ifA,Alex Band,CNot when the function is created, then the function is basically useless. Because the caller does not knowA,Alex Band,CWhat they are, even don’t know their existence.