Today I have found a strange way of adding 2 numbers in javascript:
Basically the call of the method looks this way: add(5)(6)
and the declaration of the method is:
function add(x) {
return function(y) { return x + y; };
}
Ok, I got it. The add
function does not return a number, but returns the anonymous function which adds the first number with the second. But what is the point (how it can be helpful)?
Where exactly can it be useful apart from puzzling other people or writing some sort of obfuscated malware?