Demystifying JavaScript Closures, Callbacks and IIFEs

Okay - I was misled by the completely incorrect description of what a closure actually is and missed that after the first supposed closure example that didn’t include a closure that the subsequent examples started to use one. A very confusing article about closures.

There are basically three ways to create a closure

example1 = function(x) {
var myvar1 = x;
return function() {return myvar1;};
}

var aa;
example2 = function(y) {
var myvar2 = y;
aa = function() {return myvar2;};
}

example3 = function(z) {
var bb, myvar3;
bb = function() {return myvar3;};
myvar3 = z;
return bb;
}