The "promise" gets fulfilled with `deferred.resolve()` at the end of the else clause. `deferred` is the underlying `$.Deferred()` object for the promise (`deferred.promise()`). Only code allowed to resolve/reject the promise has access to the underlying deferred object. Code with access to the promise can only execute code on done/fail/always. That's why deferred is created in this function, but only the promise is returned.