- We are creating a file named main.js and app.js.
- In the app.js file, we are importing the main.js.
- In app.js, We are creating an element named “script” and setting its source link equal to the main.js.
- Then we are appending that “script” element into the head of the app.js file.
- After loading the file into the browser it shows the alert first.
Main file: This file will import the above “main.js” file
- In this approach, we are creating three files named main.js, second.js, and master.js.
- master.js file is importing the rest of the two files by using include function.
- We are setting the src eqaul to the file link.
- After loading the file it shows the output accrding to the written code in both of the imported files.
"Welcome to Geeksforgeeks"
Main file: This file will import the above “master.js” file
Output: It is showing both the alerts from main.js and second.js according to the sequence of including both of the files in master.js.
Share your thoughts in the comments
Please Login to comment...