<html>
<head>
<script src="./first.js"></script>
<script src="./second.js"></script>
</head>
</html>
In the first.js file, I want to call the functions from second.js:
secondFun(); // calling a function from second.js file
This is second.js file:
function secondFun() {
console.log('second function called!!')
}
tl;dr: Load your dependencies before you depend on them.
You can't call a function that hasn't been loaded.
The functions defined in your second JS file won't be loaded until the first file has finished running all the top-level statements.
Reverse the order of your script elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With