亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

js關于操作符

js關于操作符

慕田峪9158850 2018-09-12 14:14:05
直接上代碼var num = '123'; console.log( ++num );輸出124我能理解console.log( ++'123' );報錯Uncaught ReferenceError: Invalid left-hand side expression in prefix operation為什么只是一個是存入變量就不會報錯 一個是直接暴露出來 就報錯
查看完整描述

1 回答

?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

你搞錯了自增/自減符號的運算意義
它們的共同點是,把自身+1或者是-1之后的值賦值給自己,注意,是要把結果賦值給自己的。
那么你弄個常量來進行自增自減怎么可能不報錯……

規范在這里,你可以參考一下:

UnaryExpression : ++ UnaryExpression

  1. Let expr be the result of evaluating UnaryExpression.

  2. Let oldValue be ToNumber(GetValue(expr)).

  3. ReturnIfAbrupt(oldValue).

  4. Let newValue be the result of adding the value 1 to oldValue, using the same rules as for the + operator (see 12.7.5).

  5. Let status be PutValue(expr, newValue).

  6. ReturnIfAbrupt(status).

  7. Return newValue.

PostfixExpression : LeftHandSideExpression ++

  1. Let lhs be the result of evaluating LeftHandSideExpression.

  2. Let oldValue be ToNumber(GetValue(lhs)).

  3. ReturnIfAbrupt(oldValue).

  4. Let newValue be the result of adding the value 1 to oldValue, using the same rules as for the + operator (see 12.7.5).

  5. Let status be PutValue(lhs, newValue).

  6. ReturnIfAbrupt(status).

  7. Return oldValue.


查看完整回答
反對 回復 2018-10-09
  • 1 回答
  • 0 關注
  • 632 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號