Promise.reject()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
O método Promise.reject(motivo)
retorna um objeto Promise que é rejeitada com um dado motivo.
Sintaxe
Promise.reject(motivo);
Parâmetros
- motivo
-
Motivo pelo qual este Promise foi rejeitado.
Descrição
O método estático Promise.reject
retorna uma Promise
que é rejeitada. Para fins de debug e captura de erros seletiva, é útil que o motivo seja uma instanceof
Error
.
Exemplos
Usando o método estático Promise.reject()
js
Promise.reject("Testando reject estático").then(
function (motivo) {
// não executado
},
function (motivo) {
console.log(motivo); // "Testando reject estático"
},
);
Promise.reject(new Error("falha")).then(
function (erro) {
// não executado
},
function (erro) {
console.log(erro); // Stacktrace
},
);
Especificações
Specification |
---|
ECMAScript® 2025 Language Specification # sec-promise.reject |
Compatibilidade com navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reject() |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.