Functions are synchronous. Period.
What can be asynchronous is an (abstract) process/workflow.
When someone says a function is "async" what they actually mean is that the result will be available some time later. The result is wrapped in a Promise, which is a handle to await. But the process may still be synchronous. Have a look at this example:
function foo() {
return new Promise((res, rej) => {
console.log(1);
console.log(2);
res();
});
};
function test() {
foo();
console.log(3);
};
and the output is always the same:
> test();
1
2
3
which means that each function was called one after another in a synchronous manner. And indeed if you update foo function to:
function foo() {
return new Promise((res, rej) => {
while (true) {}
res();
});
};
you will notice that console.log(3) never runs. And so our foo blocks forever!
Now have a look at this example:
function test() {
Promise.resolve().then(function() {
console.log(1);
console.log(2);
});
console.log(3);
};
and note the different result: 3 1 2. All those functions are synchronous, so why the order is different? Because .then() postpones the execution to some later time.
All in all: sync/async is not really a property of a function, but rather a property of a workflow. And in your case it is synchronous.
Side note: this gets more complicated when exceptions are involved. Let's modify the foo function from the first example:
function foo() {
return new Promise((res, rej) => {
throw 'myException';
});
};
function test() {
foo();
console.log(3);
};
and call test(). Oh, wow, now 3 is first (someone may think that it should not be executed at all!!!) and the uncaught exception myException second. Why? Because JavaScript engine postpones exception handling. Don't ask me why, I have no idea, but I'm sure there is a reason for this... like for everything. ;)
Conclusion: Promises don't make things automatically asynchronous and always await or use .then() with a function that returns a Promise (unless you're a ninja).