What is the differences between async await and then in javaScript

preview_player
Показать описание
First HTML File
✔ Uses basic JavaScript (.then()) for fetching data.
✔ No styling (CSS) included.
✔ Uses an event listener for the button (addEventListener).
✔ Function is called on page load to display an image.

Second HTML File
✔ Uses async/await for a cleaner, modern way of handling asynchronous code.
✔ Includes CSS styling (centered text, styled button, image with rounded corners).
✔ Uses inline event handling (onclick="fetchRandomDogImage()") for the button.
Second version is better because:

Uses async/await, making code easier to read.

Has better error handling.

Includes CSS for a better user experience.

🤔 First version is still good if you prefer .then(), but it lacks styling and proper error checks.
Рекомендации по теме
Комментарии
Автор

Apreciez explicarea doar ca n-am norocul sa programez pe JavaScript asa ca aia e, mișto ar fi sa învăț și asta

Gavriasagmaeilll
welcome to shbcf.ru