Recently I saw this piece of JavaScript code, but have been unable to understand what it is trying to do.
var f = function(a) {
return function() {
alert(a());
};
};
f(function() { return "Hello World"; })();
Please explain what this accomplishes!
It executes the function that f returns.
f returns a function that calls an alert that displays the output of the function you gave as parameter to f.
EDIT:
Just substitute some parts to make it easier on the eye and you will see yourself: