| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Unary_plus | [Back] [Original] |
Get to know MDN better
const x = 1;
const y = -1;
console.log(+x);
// : 1
console.log(+y);
// : -1
console.log(+"");
// : 0
console.log(+true);
// : 1
console.log(+false);
// : 0
console.log(+"hello");
// : NaN
+x
(-)
truefalsenull 10 16 0x 16 NaN + TypeError
const x = 1;
const y = -1;
console.log(+x);
// 1
console.log(+y);
// -1
+true // 1
+false // 0
+null // 0
+[] // 0
+function (val) { return val; } // NaN
+1n // TypeError: Cannot convert BigInt value to number
| ECMAScript 2027 LanguageSpecification # sec-unary-plus-operator |
| Web Proxy Viewer | New URL | Original Page |