Js closure scope

recently, when I was looking at the design pattern, I encountered a problem about closures. I can"t figure it out. Ask for help. The code is as follows:

function foo(){
    var a = 10;
    function bar(){
        a*= 2;
        return a;
    }
    return bar;
}

var baz = foo();
console.log(baz.toString());


var blat = foo();
console.log(blat.toString());

console.log(baz==blat)

printed result:

clipboard.png

:


:

clipboard.png

aaccbazblat
Jul.30,2021

var baz = foo();
var blat = foo();
returnbaz = foo();
return

the first paragraph of code does not point to the same reference. If you call foo, twice, each call will define a new bar function


baz and blat don't point to the same reference, do you


pay attention to the difference in performing assignments, although I can't explain it very well, if anyone makes sense to you, Remember to tell me about


Brother. The closure you first wrote returns the function body, but you don't write a function body. The two are not comparable at all.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3513b-2bf5f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3513b-2bf5f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?