How to import JS in HTML
<script src="app.js"></script>
defer
attribute in script tag to ensure the HTML page loads before the js file or we can add the the script tag below the HTML file
How To import and Export in js
exportfile.js
export const apiKey="ASZFWXWFWGBWFKKG"
importfile.js
import {apiKey} from "./exportfile.js"
OR
By using the default method only one value can be exported from the file. you can give any name for the imported variable
exportfile.js
export default "ASZFWXWFWGBWFKKG"
importfile.js
import apiKey from './exportfile.js'
OR
Grouping
But you can have both in single file
exportfile.js
export default "agsdgadsh";
export const data="1234";
export let admin = true;
importfile.js
import * as exp from './exports'
console.log(exp.default)
console.log(exp.data)
console.log(exp.admin)
Top comments (0)