Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
"variable" is not defined OR Cannot access 'app' before initialization

I'm trying to call a method from a "utils" file that contains functions, but I have this error :

Uncaught ReferenceError: utils is not defined

I checked my index.html, it does contains :

    <script src="js/app.js"></script>
    <script src="js/utils.js"></script>

So I tried to reverse those 2 lines :

    <script src="js/utils.js"></script>
    <script src="js/app.js"></script>

But then I get a new error :

app.js:7 Uncaught ReferenceError: Cannot access 'app' before initialization

Here is my app.js and util.js :

const app = {
    rowsNb: 4,
    columnsNb:6,

    rowPosition: utils.getRandomNumber(1, app.rowsNb),
    columnPosition: utils.getRandomNumber(0, app.columnsNb - 1),

    init: () => {
        console.log('init');
        app.drawBoard();

        document.addEventListener('keydown', app.handleKeydown);
        document.getElementById('launchScript').addEventListener('click', app.handleLaunchScriptButton)
    }, 
    
    ...

   document.addEventListener('DOMContentLoaded', app.init);
const utils = {
    getRandomNumber: (min, max) => {
        let randomNumber =  Math.random() * (max - min) + min;
        return Math.round(randomNumber);
    }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!