【问题标题】:why do i get a syntax error from the console?为什么我从控制台收到语法错误?
【发布时间】:2021-06-23 11:07:50
【问题描述】:

为什么我会从控制台收到语法错误?它告诉我第二个整数已经被声明了,但我只声明了一次

function performOperation(secondInteger, secondDecimal, secondString) {
   const firstInteger = 4;
   const firstDecimal = 4.0;
   const firstString = "HackerRank "
   const secondInteger=5;
   const secondDecimal=2.0;
   const secondString="hacking rank";
  console.log(firstInteger+ secondInteger); 
  console.log(firstDecimal+secondDecimal);
  console.log(firstString+secondString);}

【问题讨论】:

  • secondInteger 是此处的参数,因此无需在secondInteger 之前添加const

标签: javascript syntax


【解决方案1】:

参数名称是变量声明,因此您需要声明两次。

  1. 在第 1 行作为参数名称
  2. 再次在第 5 行作为const

【讨论】:

    猜你喜欢
    • 2022-11-28
    • 2011-08-22
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    • 2020-09-04
    • 2022-01-23
    相关资源
    最近更新 更多