In this case, it is not clear what type is returned in the last line?
What is it, an array of functions?

function Calculator() { var methods = { "-": function(a, b) { return a - b; }, "+": function(a, b) { return a + b; } }; this.calculate = function(str) { var split = str.split(' '), a = +split[0], op = split[1], b = +split[2] if (!methods[op] || isNaN(a) || isNaN(b)) { return NaN; } return methods[op](a, b); 

    1 answer 1

    The string passed to this.calculate is this.calculate by spaces, where a and b typed into numbers, and op , in turn, contains an operation (specifically, there can only be addition and subtraction - they are pre-registered in the local object methods ) Then it is checked - there is whether the specified operation is in the methods object and whether the transmitted numbers are a & b NaN. (if at least one of these is true , the execution result becomes NaN)
    If this is not the case, the required function is called by a key from the methods object, which accepts two numbers with input data and returns the result of the execution. (addition or subtraction specifically in your example.)

    UPD. as suggested in the comments, it is worth clarifying - the type of the return value is always number .

    • Fine! But I think that you forgot to clarify - the type of the return value: number (NaN too ) - UModeL
    • @UModeL, Oops, yes, I missed this moment. Qayus, do not hit, the rules of the answer;) - ya.ymer