How to access javascript file from another javascript file linked with same html file ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to access javascript file from another javascript file linked with same html file ?

if I have a html file i.e index.html and two javascript files first is script1.js and second one is script2.js. how can I access functions from script1.js from script2.js. if I have a function in script1.js is function add(a,b){return a+b} , I want to access this function from script2.js just like a library how can I do that.

30th Oct 2020, 7:08 AM
Vaibhav Pawar
Vaibhav Pawar - avatar
1 Answer
+ 5
By exporting functions from first script and importing it from second. More on modules https://www.sololearn.com/learn/JavaScript/2981/
30th Oct 2020, 7:10 AM
Raj Chhatrala
Raj Chhatrala - avatar