Ad
  • Custom User Avatar

    To return a function, you simply... return a function!! :)

    For example:

    function MagicFunction(...a) {
      function toBeReturned(...a) {
        do {
          // this code...
        } while (somethingIsTrue);
        return something;
      }
    
      return toBeReturned;    // This is how to return a function..
      return toBeReturned();  // This would be, instead, returning a function invocation..
    }