This calls the .then function asynchronously (the 'THEN' string is logged in the last spot of the array)
const array = [];
array.push('before');
new Promise(resolve => {
array.push('promise');
resolve();
}).then(()=>array.push('THEN'));
array.push('after');
console.log(array)
//RESULT: ["before", "promise", "after", "THEN"]
But if instead of a function I pass a method .then is called synchronously
const array = [];
array.push('before');
new Promise(resolve => {
array.push('promise');
resolve();
}).then(array.push('THEN'));
array.push('after');
console.log(array)
//RESULT: ["before", "constructed", "THEN", "promise"]