Ad
  • Custom User Avatar

    It's good you've found working solution. Take a look at Matija7's answer to see cleaner solution.

  • Custom User Avatar

    Nice.

    Regarding var result = 0;
    You can just declare result variable. IMHO this is better option for readability of your code.
    var result;
    Or you can initialize it to default value and loose else block.
    var result = null;

    However, you could improve formatting.
    result= a + b; => result = a + b;

    Closing if and elese if block brace should be aligned with block key word.

    else if(o === "-") {
      result = a - b;
      }
    
    else if(o === "-") {
      result = a - b;
    }
    

    You don't need last return statement return result; since all your if statement blocks return value;