No, you cannot return
the result from an asynchronous call.
Assigning them to a global (or higher-scope) variable, such as subFolderData
or rootData
in your example, is possible, but does not make sense because you do not know when the value will be available.
Storing the promises for the values, like your ajaxModule.subFolderFile
and ajaxModule. rootFile
, and always incorporating them when needing to access the data, is the way to go.