There will be for sure a duplicate for this question, but I'd like to have an answer for this specific piece of code. I have this function:
var somevar = "";
some.method({
...
}).then(function (data) {
somevar = "Hello";
}).catch(function (error) {
somevar = "Error";
});
console.log(somevar);
And at the end it will always print an empty string instead of the values that I'm trying to assign (for sure the program is going in the "then" or "catch" code block). Why this is happening? It seems to be a stupid question, but actually sometimes I have these kind of problems. I know how this stuff works (hoisting, scopes, assignment etc.) but sometimes I find myself in troubles and so I decided to ask here once and for all.