filmov
tv
JavaScript How to import a function from a module to the main script?
Показать описание
There is a site with the main script.
To use the import statement we gotta set the type of main script to module.
There is another JS-file with a function.
Let this function return an inverted value.
This file is a separate module.
The module exports the inverse function.
In the main script we import the inverse function from the helper module.
Let’s use it and log out the inverted value of 2.
To run the site we need a web-server.
The live-server will do.
Let’s get it started.
So, here is the answer.
To use the import statement we gotta set the type of main script to module.
There is another JS-file with a function.
Let this function return an inverted value.
This file is a separate module.
The module exports the inverse function.
In the main script we import the inverse function from the helper module.
Let’s use it and log out the inverted value of 2.
To run the site we need a web-server.
The live-server will do.
Let’s get it started.
So, here is the answer.