I read the ECMAScript 5.1 specification . It says:
The slice method takes two arguments: start and end [...]. If the beginning is negative, it is considered as length + start, where length is the length of the array. If the end is negative, it is considered as length + end, the length of which is equal to the length of the array.
What does negative mean? It makes sense that, like in math,
- If
num > 0 , then num positive - If
num < 0 , then num negative.
But what about +0 and -0 ? In mathematics, there is one 0 that is not positive and negative. I assumed in ECMAScript
+0 (aka positive zero) is positive.-0 (negative zero aka) is negative.
But I tried using -0 with slice , and browsers see it as non-negative.
Then, are both +0 and -0 non-positive and non-negative, despite their names?
Where is the positive or negative of a certain number? I did not find this in the ECMAScript specification. Is the definition inherited from IEEE 754?
javascript language-lawyer specifications
Orientol
source share