[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Unary_plus [Back]  [Original]

(+) - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

(+)

Baseline

20157

(+)

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

js
+x

(-)

truefalsenull 10 16 0x 16 NaN + TypeError

js
const x = 1;
const y = -1;

console.log(+x);
// 1
console.log(+y);
// -1

js
+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