Unlock Top Level Await in JavaScript with Module Type

Things that i got to know about that you can use the `await` keyword without even being inside the function and don't even need the `async` keyword. It is completely independent. It is know as ** Top Level Await **.The only requirement is that in your html file you have to tell that you're going to use javascript as module type: ```html <script src="index.js" type="module"></script> ``` and now you can use await without even depending on function and async keyword. ```js const response = await fetch("https://lnkd.in/gKkcr_rj"); const data = await response.json(); console.log(data); ``` There you go, now you don't have to use async on the promises returned function. all you need is just to use await and make sure that you've specified the type of "module". #javascript #web-development

To view or add a comment, sign in

Explore content categories