I'm working through Kyle Simpson's "You Don't Know JavaScript" series. At the end of (published 2014) "Scope & Closures" (p. 62), there is an example in ES6 of using the keyword "module" to import an entire module, like so:
// import the entire "foo" and "bar" modules
module foo from "foo";
module bar from "bar";
console.log(
bar.hello( "rhino" )
);
foo.awesome();
This code doesn't work, however. My question is: is the module
keyword something that was experimented with and dropped? Should I forget about this keyword?
We can declare a module by using the export keyword. The syntax for the module declaration is given below.
A module is a single JavaScript file that has some reasonable functionality. A package is a directory with one or more modules inside of it and a package. json file which has metadata about the package.
For hardware, a module is an assembly of parts designed to be added and removed from a larger system easily. An example of a hardware module is a stick of RAM. Most modules are not functional on their own. They need to be connected to a larger system or be part of a system made up of several modules.
<script type=module> allows loading of JavaScript modules inside web pages.
They're typos
// import the entire "foo" and "bar" modules
import foo from "foo"; //fixed
import bar from "bar"; //fixed
console.log(
bar.hello( "rhino" )
);
foo.awesome();
Sometimes, the examples in a book are not 100% accurate in typo, they really make confusion for the beginners.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With