I am quite a beginner with javascript and node.js, so forgive me if the question can be considered as too simple.
I was wondering, if I have a function that returns a Promise, and in its resolve() it calls again the same function in a sort of recursion, can this cause a stack overflow in case it does not get resolved?
You can imagine it as it follows:
var someVariable = await myFunction(someInput)
async function myFunction(myInputValue) {
return new Promise(function(resolve, reject) {
// do some computation
if (someCondition) {
resolve(true)
return
} else {
resolve(myFunction(myInputValue))
return
}
})
}
I was asking this since I noticed the return instruction gets executed, and this should (in my opinion) deallocate the function's context stack and avoid getting issues like stack overflows. Am I missing something and then I am risking issues or am I right and this can be considered quite safe as practice?