Coerce to number

后端 未结 4 942
半阙折子戏
半阙折子戏 2020-12-15 17:35

I have often seen the trick

after = +after;

to coerce the variable after to a number. Reading through the Node.JS source I fou

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 18:13

    After a quick google to make sure my suspicions were true, I came to this conclusion. Using the + operator to convert to a number is faster, because no mathematical operations occur after type-casting, whereas using the *= approach means that after after is converted, it will be multiplied by 1.

提交回复
热议问题