Why does my Promise definition gets executed?
That is simply how promises are defined. They run their executor function immediately. It's in the spec: Promise(executor), step 9.
This is an instance of the revealing constructor pattern; reading that might help you understand.
That occurs because a promise will execute immediately and synchronously.
.then()
add functions that will be executed when the promise is either fulfilled (resolve
argument) or rejected (reject
argument).
with info from comments by @Kirill Slatin