0
Javascript
How can i link a javascript file(external) to an html file for them to run together
1 Antwort
0
Aymen Esam-Aldin is right but in sololearn you cant link new file or your another project, only libs which can be gotten by link
if your script required to use addEventListener or another fn that needs to use DOM elements you should put <script> under the body tag
for ESMA or NodeJS you shold use
export function / export default function
OR
module.exports = {} / module.exports = function/class
then import them like a
import { fn } from './file.js' / import fn from './file.js'
OR
const fn = require('./file.js') / const {fn} = require('./file.js')