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

198
Views
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
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!