2025年9月1日 星期一

關於 Unary plus (+)

 關於 Unary plus (+)

前言

  在之前的 關於 Unary negation (-) 了解 Unary negation ,這次來學習它的相似處理 Unary plus,在此把學習的過程做個紀錄。


內容

  範例如下

let num = -4;
console.log( +num );//-4
console.log( +"123" );//123
console.log( +"-456" );//-456
console.log( +"ABC" );//NaN


Unary plus 用起來跟 Unary negation 是一樣的!在 Numbe 有加跟沒加是一樣的, Unary negation  還有負負得正的作用。在 String 方面也是會對可以 Parse 成 Number 的內容做轉換,如果不能則回傳 NaN。


參考資料

[ developer.mozilla.org ] Unary plus (+)


相關文章與資料

關於 Unary negation (-)

沒有留言:

張貼留言