Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9168471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:38:00+00:00 2026-06-17T15:38:00+00:00

I am trying to separate the logic of my application by using multiple javascript

  • 0

I am trying to separate the logic of my application by using multiple javascript files that focus on certain specific tasks.

The functions defined within the JSfiles need to be accessed between the files themselves.

I understand that the order of calling the functions is important and defining “global” vs “local” scope is important. In the following files the files are not wrapped in functions so I suppose they are in the global scope.

file1.js

function addingToDOM(stuff) {
...  
...
}

file2.js

// call addingToDOM
addingToDOM(someStuff);
function doOtherTHings() {
...
...
}

HTML (order of files)

<script src="file1.js"></script>
<script src="file2.js"></script>

ERROR
addingToDOM is not defined

file2.js calls file1.js after file1.js in the HTML.
I don’t understand why it’s not defined.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:38:01+00:00Added an answer on June 17, 2026 at 3:38 pm

    Your JS files should just define functions and call ones that are in the same JS file. If you’re going to call functions in a JS file from another, that JS file needs to be loaded first. I would put all the calling code (kind of like your “main” function in other languages like C) in one place, preferably at the end of your html document. After all, the other JS files (and the markup) is loaded. It’s not that you can’t call a function in file1 from file2, it’s that they should both be fully loaded before your code begins to run.

    Your setup should work as it is, but be sure to call the first function that needs to be run not from within a JS file, but at the end of your HTML document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to separate my logic for better readability and re-useability. I am
I'm trying to basically trying to separate a specific amount of text from the
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
I'm trying to write an android application that has two main activities: login screen
I'm trying to show information about user in my Zend Framework application. I'm using
I am trying create a small web application that allows a user to login
I am using jboss-as-7.1.0.Final-SNAPSHOT and trying to set up custom login module that uses
I am trying to separate a few things in here. I have a program
I trying to set separate style for particular widgets, like for one button with
Trying to create a black line in my view to separate text blocks but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.