Fact: when you do var inner = function() { console.log(x); }in your first line, xnot defined. What for? Because innerthere is no local x declaration inside your function (which would be done with var x = something). Then the runtime will look in the next area, that is, in the global area. There is also no declaration x, therefore xalso not defined there.
, x, 4 IIFE. IIFE x , . , , console.log() x, IIFE, .
, inner, . , , x ( ), x , inner. , x , , .
, , inner IIFE, x, inner, , x , , , x , . , .
, , console.log() inner, inner, :
var inner = function(x) { console.log(x); }
(function(cb) { var x = 123; cb(x); })(inner);