Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
"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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda