I might try to avoid having these global variables, lets look into why we need them.
let prevResult = null;
let currentOperation;
So it looks like we are reassigning prevResult
in the executeOperation
method within the Calculator
class. Do we reassign elsewhere?
Ah so we do it as part of our clear procedure.. so I guess the first thing I would do here is rather than just doing these reassignments
globally. So maybe an approach here would be to move the prevResult
global variable as a property of the Calculator
class. Then
using the constructor to set the default value to undefined
.