To give add.js and multiply.js in main.js, we have to export it first as shown below − I have three files add.js that adds 2 given numbers, multiply.js that multiplies two given numbers and main.js, which calls add and multiply, and consoles the output. ExampleĬonsole.log("%c"+a,"font-size:30px color:green ") Ĭonsole.log("%c"+b,"font-size:30px color:green ") Let us consider an example to understand how to use module and how to export it to make use of it in the code. In simpler terms, the modules help you to write the code in your module and expose only those parts of the code that should be accessed by other parts of your code. The functions or variables in a module are not available for use, unless the module file exports them. ES6 comes to your rescue with the concept of Modules.Ī module is nothing more than a chunk of JavaScript code written in a file. ModulesĬonsider a scenario where parts of JavaScript code need to be reused. In this chapter, we will see how to transpile ES6 modules to ES5 using Babel.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |