var promise1 = new Promise(resolve => setTimeout(resolve, 5000, 123));
setTimeout(_ => {
promise1.then(console.log)
}, 500);
The functions supplied will be queued up and fired once the promise resolves. It will also return a new promise which will be fulfilled or rejected with the return value of said functions.
If the promise is already settled, the functions will be fired on the next tick on the event loop.
In your example, the function supplied will still log it 5 seconds after the promise is made, which is 4.5 seconds after the second timeout is called.