JavaScript Promises - reject vs. throw JavaScript Promises - reject vs. throw javascript javascript

JavaScript Promises - reject vs. throw


There is no advantage of using one vs the other, but, there is a specific case where throw won't work. However, those cases can be fixed.

Any time you are inside of a promise callback, you can use throw. However, if you're in any other asynchronous callback, you must use reject.

For example, this won't trigger the catch:

new Promise(function() {  setTimeout(function() {    throw 'or nah';    // return Promise.reject('or nah'); also won't work  }, 1000);}).catch(function(e) {  console.log(e); // doesn't happen});