ä¸å è² èéç®åï¼-ï¼
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 = 4;
const y = -x;
console.log(y);
// Expected output: -4
const a = "4";
const b = -a;
console.log(b);
// Expected output: -4
èªæ³
js
-x
ç¯ä¾
>è½ææ¸å
js
const x = 3;
const y = -x;
// y = -3
// x = 3
è½æéæ¸å
ä¸å è² èéç®åå¯ä»¥å°éæ¸åè½çºæ¸åã
js
const x = "4";
const y = -x;
// y = -4
è¦ç¯
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-unary-minus-operator> |