javascript async fetch file html 1

javascript async fetch file html

async function () {
element.innerHTML = await (await fetch('./filetofetch.html')).text();

Here is what the above code is Doing:
1. The async keyword before a function has two effects:
1. It allows the function to use the await keyword.
2. It ensures that the function returns a promise.
2. The await keyword before a promise makes JavaScript wait until that promise settles, and then:
1. If it’s an error, the exception is generated.
2. If it’s a value, it becomes the result of the operation.
3. The await keyword can only be used inside an async function.

Similar Posts