Edit in JSFiddle

<input readonly id="output"/>

              
function add(a) {

  let currentSum = a;

  function f(b) {
    currentSum += b;
    return f;
  }
  
  f.valueOf = function() {
  	return currentSum;
  }

  return f;
}

document.getElementById('output').value = add(1)(2)(3)(4) + 3