Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Creating Custom Promises | Mastering Promises
Asynchronous JavaScript Explained

bookCreating Custom Promises

script.js

script.js

index.html

index.html

copy

When you create a custom Promise like checkNumber, you can control how and when it resolves or rejects. The function above returns a new Promise that checks if a given number is greater than 10. If the condition is met, it calls resolve with a success message; otherwise, it calls reject with an error message. To handle the outcome of this Promise, you use the .then method to respond to a successful resolution, and the .catch method to handle a rejection. For instance, calling checkNumber(15) would trigger the .then block, while checkNumber(5) would trigger the .catch block. This pattern helps you manage asynchronous results and errors in a clean and predictable way.

question mark

Which method is used to handle a rejected Promise?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 4

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Awesome!

Completion rate improved to 3.57

bookCreating Custom Promises

Swipe um das Menü anzuzeigen

script.js

script.js

index.html

index.html

copy

When you create a custom Promise like checkNumber, you can control how and when it resolves or rejects. The function above returns a new Promise that checks if a given number is greater than 10. If the condition is met, it calls resolve with a success message; otherwise, it calls reject with an error message. To handle the outcome of this Promise, you use the .then method to respond to a successful resolution, and the .catch method to handle a rejection. For instance, calling checkNumber(15) would trigger the .then block, while checkNumber(5) would trigger the .catch block. This pattern helps you manage asynchronous results and errors in a clean and predictable way.

question mark

Which method is used to handle a rejected Promise?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 4
some-alt