ë¨í ëí기 (+)
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 7ì.
ë¨í ëí기 ì°ì°ì(+)ë í¼ì°ì°ì ìì ìì¹íë©° í¼ì°ì°ì를 íê°íì§ë§, ë§ì½ í¼ì°ì°ìê° ì«ìê° ìëë¼ë©´ ì«ìë¡ ë³íì ìëí©ëë¤.
ìëí´ ë³´ê¸°
const x = 1;
const y = -1;
console.log(+x);
// Expected output: 1
console.log(+y);
// Expected output: -1
console.log(+"");
// Expected output: 0
console.log(+true);
// Expected output: 1
console.log(+false);
// Expected output: 0
console.log(+"hello");
// Expected output: NaN
구문
+x;
ì¤ëª
ë¨í ë¶ì (-)ë ì«ìê° ìë ê°ì ë³íí ì ìì§ë§, ë¨í ëí기ë
ì´ë¤ ê²ì ì«ìë¡ ë³ííë ê°ì¥ ë¹ ë¥´ê³ ì í¸íë ë°©ë²ì
ëë¤. ìëíë©´ ì«ìì ëí´ ë¤ë¥¸ ì°ì°ì ìííì§ ì기 ë문ì
ëë¤.
ì ìì ì¤ìì 문ìì´ ííë¿ ìëë¼ ë¬¸ìì´ì´ ìë ê°ì¸ true, false ë° null ëí ë³íí ì ììµëë¤.
10ì§ì ë° 16ì§ì(0x ì ëì¬) íìì ì ì 모ë ì§ìë©ëë¤. ììë ì§ìë©ëë¤(16ì§ì ì ì¸).
BigInt ê°ì ì°ì°ì를 ì¬ì©íë©´ TypeErrorê° ë°ìí©ëë¤. í¹ì ê°ì 구문 ë¶ìí ì ìì¼ë©´ NaNì¼ë¡ íê°ë©ëë¤.
ìì
>ì«ìì ì¬ì©í기
const x = 1;
const y = -1;
console.log(+x);
// 1
console.log(+y);
// -1
ì«ìê° ìë ê°ì ì¬ì©í기
+true; // 1
+false; // 0
+null; // 0
+function (val) {
return val;
}; // NaN
+1n; // TypeError ë°ì: BigInt ê°ì ì«ìë¡ ë³ê²½í ì ììµëë¤
ëª ì¸
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-unary-plus-operator> |