I have read that a when you return a value from then() it gets wrapped in a Promise and gets returned as a promise. Is there a way to return just a value and NOT a promise object?
function TestPromise() {
//someAsyncFunction returns a Promise.
return someAsyncFunction();
}
//Assume valueFromPromise = 2;
//After the addition newValue becomes 3
//And we return 3 instead of 3 wrapped up in a Promise.
function someFunction() {
return latestValue = TestPromise().then(valueFromPromise => {
newValue = valueFromPromise + 1;
return newValue;
});
}
function main() {
let value = someFunction();
//Use value here to do something.
}
I know what I am asking can be achieved via async/await. But I want to properly understand Promises.
Thanks