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
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.
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.
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.