DEV Community

101samovar
101samovar

Posted on

How to import a function from a module to the main script?

There is a site with the main script.
101samovar
To use the import statement we gotta set the type of main script to module.

There is another JS-file with a function.
101samovar
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.
101samovar

To run the site we need a web-server.
The live-server will do.
101samovar

Let’s get it started.
So, here is the answer.
101samovar


I hope you found this article useful, if you need any help please let me know in the comment section.

👋 See you next time. Have a nice day!

Subscribe to our channel:
https://www.youtube.com/c/Samovar101

Discussion (0)