Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
Cannot access before initialization using Node JS and Chrome

I have three js files as below

index.js

function getNumberToDisplay(){
    document.getElementById("currentDay").innerHTML = getNumber();
}

checkDay.js

const randomDate = require("./randomDate");
module.exports = {};
function getNumber(){
    return randomDate.getSmallNumber();
}
module.exports.getNumber = getNumber;

randomDate.js

module.exports = {};
function getSmallNumber(){
    return 3;
}
module.exports.getSmallNumber = getSmallNumber;

I also have a html page which has a button which calls the getNumberToDisplay function. All 3 scripts are included in the html page by using the tags. When I press the button to call getNumberToDisplay I get the error Uncaught ReferenceError: Cannot access 'randomDate' before initialization

What is it that I am missing in order to be able to get the button to execute the function? The tests of the functions return the expected results in Jest, but the button doesn't work when opening the html page in Chrome.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda