相減運算子(-)
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
相減運算子(-
)是用來將兩個值進行相減,並得出它們的差值。
嘗試一下
語法
js
x - y
範例
數字相減
js
5 - 3; // 2
3 - 5; // -2
非數字之間的相減
js
"foo" - 3; // NaN
規範
Specification |
---|
ECMAScript Language Specification # sec-subtraction-operator-minus |
瀏覽器相容性
BCD tables only load in the browser