When I use '=' in my if statement I get undefined, but when I use '===' I get my expected result. Can someone explain what's happening there?
function once(callback) {
let counter = 0;
let result;
function sum(x) {
if (counter === 0) {
result = callback(x);
counter++;
}
return result;
}
return sum;
}
const addByTwoOnce = once(function(num) {
return num + 2;
});
// UNCOMMENT THESE TO TEST YOUR WORK!
console.log(addByTwoOnce(5)); //should log 7
console.log(addByTwoOnce(10)); //should log 7
console.log(addByTwoOnce(9001)); //should log 7