How it works...

Although our browser can work with ES modules, we still need to specify that is how we want our code to be loaded. The older way of including script files uses type="text/javascript". This tells the browser to execute the content of the tag immediately (either from tag contents or from the src attribute).

By specifying type="module", we are telling the browser that this tag is an ES module. The code within this tag can import members from other modules. We imported the function sayHi from the hello module and executed it within that <script> tag. We'll dig into the import and export syntax in the next couple of recipes.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.