Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript module keyword

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?

like image 277
zumafra Avatar asked Oct 04 '18 02:10

zumafra


People also ask

Which keyword is used to declare a module?

We can declare a module by using the export keyword. The syntax for the module declaration is given below.

What are modules packages JavaScript?

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.

What is module example?

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.

What does type module do?

<script type=module> allows loading of JavaScript modules inside web pages.


1 Answers

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.

like image 124
You Nguyen Avatar answered Oct 11 '22 19:10

You Nguyen