closures

i thought I should write a bit about closures. Closures are awesome. I mean, how many times does a function bring with it the data associated with it after it is called? I want to illustrate what I mean by bringing the data with it.

function foo() {
    let x = 32;
    return function() {
	console.log(x);
    }
}

if you look at the code above, the value x will last as long as the function hello is running. After the code runs, x should ideally be garbage collected. And this is the case with most functions. But then, closures give the ability for x to live long after the function is called.

let bar = hello();
bar(); // this will log 32

That's crazy, right? I mean x should have been garbage collected long before.

You might be wondering what the fuck is this article doing here? this was after all advertised as a poetry blog. But then again, closures are just pure poetry.