Edit in JSFiddle

//the mathOperation function returns a function
var mathOperation = function (operatorAsString) {
    switch (operatorAsString) { //return a function
        case '+': return function(x, y) { return x + y; };
        case '+': return function(x, y) { return x + y; };
        case '-': return function(x, y) { return x - y; };
        case '*': return function(x, y) { return x * y; };
        case '/': return function(x, y) { return x / y; };
    };
};

console.log(mathOperation('+')(2, 2)); //logs 4
console.log(mathOperation('*')(2, 2)); //logs 4