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

325
Views
Uncaught TypeError: a is undefined

I have this:

let dateDataStartDate = moment().startOf('week')._d
let dateDataEndDate = moment().endOf('week')._d
if (datesData.start != undefined) {
  dateDataStartDate = datesData.start
  dateDataEndDate = datesData.end
}

axios.get('/api/classes/' + props.myVal, {
      params: {
          dateDataStartDate: dateDataStartDate,
          dateDataEndDate: dateDataEndDate,
          admin: true
      }
  })

when I run this code, I get this error:

Uncaught TypeError: a is undefined

and this error corresponds to this line from my console output:

let dateDataEndDate = moment().endOf('week')._d

Does anyone have any idea what the problem could be?

UPDATE

Problem was solved by fixing if (datesData.start != undefined) {

what was happening was that datesData is undefined, which means the object element .start doesn't exist. So it seems that I am trying to access a non-existent object element, and it was failing. So to fix it, I did:

if (datesData != undefined) {

weird, but it works

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can tell that the error is not within your code snippet

By the time the error occurs, in your 2nd line, there is no variable a.

let dateDataStartDate = moment().startOf('week')._d
let dateDataEndDate = moment().endOf('week')._d
if (datesData.start != undefined) {
  dateDataStartDate = datesData.start
  dateDataEndDate = datesData.end
}

axios.get('/api/classes/' + props.myVal, {
      params: {
          dateDataStartDate: dateDataStartDate,
          dateDataEndDate: dateDataEndDate,
          admin: true
      }
  })

If the error really is coming from that line, then it can't be from failure to define moment(), since it got past the first line.

Therefore there must be something wrong with the moment software, and probably in its endOf() module.

As @Mithiridi Prasanth says, do check that you are using an up to date version of NodeJs.

Debugging

Remove all the lines except the line causing the error

Are you still getting the error, and in the same line?

That line is not using any variables previously declared, and the later lines can't be the cause of the earlier error, if you are right about the site of the error.

Try a less deep access into moment()

let test1 = moment()
let test2 = moment().endOf
let test3 = moment().endOf('week')
let test4 = moment().endOf('week')._d

And console.log the results. That way you can see at what stage it is going wrong.

about 4 years ago · Juan Pablo Isaza Report
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!