一元否定 (-)
一元否定 (-
) 运算符位于其操作数之前并对它求反。
¥The unary negation (-
) operator precedes its operand and negates it.
Try it
语法
描述
¥Description
-
运算符针对两种类型的操作数进行重载:编号和 BigInt。它首先 将操作数强制为数值 并测试它的类型。如果操作数变为 BigInt,则执行 BigInt 求反;否则,执行数字求反。
¥The -
operator is overloaded for two types of operands: number and BigInt. It first coerces the operand to a numeric value and tests the type of it. It performs BigInt negation if the operand becomes a BigInt; otherwise, it performs number negation.
示例
对数字求反
否定非数字
规范
Specification |
---|
ECMAScript Language Specification # sec-unary-minus-operator |
浏览器兼容性
BCD tables only load in the browser