依然是赋值

=是赋值,+代表后面的数字为正数,同理=-代表后面的数字为负数

用处

相当于告诉编译器,即将赋值的数值类型为数字类型,不要把数字当作字符串去拼接

示例

function Calculator(){
    this.read=function(){
    //此处不用=+的话,sum函数会返回数字拼接的字符串
      this.a=+prompt("a=",0);
      this.b=+prompt("b=",0);
    }
    this.sum=function(){
      return this.a+this.b;
    }
    this.multiply=function(){
      return this.a*this.b;
    }
  }

  let cal=new Calculator();
  cal.read();
  alert(cal.sum());
  alert(cal.multiply());

相关文章:

  • 2021-11-04
  • 2021-08-18
  • 2021-08-15
  • 2019-03-19
  • 2021-12-11
  • 2021-06-21
  • 2021-08-25
  • 2021-12-06
猜你喜欢
  • 2021-06-05
  • 2022-01-16
  • 2022-02-18
  • 2021-10-20
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案