JavaScript: Simple Module Example
Page 7a
Simple Module Example
When this Web page loads, the following import script executes, from the header.
The script imports module file,
export-first-header.js.
Then the script calls module function,
function popupMessage(s)
, declared in export-first-header.js
.
The only parameter to popupMessage()
is a string that says, First Module
,
however you can pass any string to popupMessage()
, in your import file.
<script type="module" > import * as m from './javascript/export-first-header.js'; // Use exported values from // export-first-header.js: m.popupMessage('First Module'); </script>
Return to Full Tutorial
Tap the left arrow button, above, the
7
button below, or
just return to
JavaScript Advanced > Modules
for more information about importing and exporting JavaScript modules.
Learn JavaScript
JavaScript's the foundation of Web developer and Website design skills. This free and unique JavaScript tutorial includes some new or seldom used, but useful features.