Why script continue excuting after an error in a promise

i have this promise without error handler

new Promise(function() {
  noSuchFunction(); // Error here (no such function)
})
.then(() => {

});


console.log("why this code is executed ?? ");

i don’t understand why the script does not crash and continue executing after the error

Answer

Promises are designed to handle asynchronous code, so they have to provide a mechanism for errors to be handled asynchronously. Consequently, they capture all errors (similar to a try/catch block) and pass them along the promise chain.

const promise = new Promise(function() {
    noSuchFunction(); // Error here (no such function)
  })
  .then(() => {

  });


console.log("why this code is executed ?? ");

promise.catch( error => console.log(error.message) );