【问题标题】:Error with assignment to constant variable分配给常量变量时​​出错
【发布时间】:2021-01-03 15:55:53
【问题描述】:

我不是开发人员,我只是使用了检查元素,但我的继父从新年开始就遇到了他的网站问题。当使用检查元素并单击损坏的按钮时,会出现“TypeError:分配给常量变量。”

代码是:

/*************************** PUBLIC VIEW ******************************/

async function displayAppointmentsFromDate(date, package, addonArray) {

    const appointments = await getAppointmentsFromDate(date);
    let html = '';
    const today = new Date();
    const thisYear = today.getFullYear();
    const thisMonth = today.getUTCMonth();
    if(thisMonth === 0) thisMonth = 12;
    const thisDay = today.getUTCDate();
    const thisDate = thisYear.toString() + '-' + thisMonth.toString() + '-' + thisDay.toString();
    const currentTime = today.toTimeString();

错误指向这行代码:

    if(thisMonth === 0) thisMonth = 12;

如果真的需要帮助,我可以扩展代码和网站 url,谢谢!

【问题讨论】:

    标签: javascript html css web


    【解决方案1】:

    使用“const”关键字声明的变量将来不能更改其值。 您应该使用“let”关键字:

    let thisMonth = today.getUTCMonth();
    

    【讨论】:

      猜你喜欢
      • 2021-03-10
      • 2020-09-15
      • 2019-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多