Can we call the function written in one JS file in another JS file? Can anyone help me how to call the function from another JS file?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The function could be called as if it was in the same JS File as long as the file containing the definition of the function has been loaded before the first use of the function.
I.e.
File1.js
File2.js
HTML
The other way won’t work.As correctly pointed out by Stuart Wakefield. The other way will also work.
HTML
What will not work would be:
HTML
Although
alertOneis defined when calling it, internally it uses a function that is still not defined (alertNumber).