I found in a previous question that Math.pow(0, 0) === 1 returns true.
In the documentation we find the following rules for x^y:
- If y is NaN, the result is NaN.
- If y is +0, the result is 1, even if x is NaN.
- If y is −0, the result is 1, even if x is NaN.
- If x is NaN and y is nonzero, the result is NaN.
- If abs(x)>1 and y is +∞, the result is +∞.
- If abs(x)>1 and y is −∞, the result is +0.
- If abs(x)==1 and y is +∞, the result is NaN.
- If abs(x)==1 and y is −∞, the result is NaN.
- If abs(x)<1 and y is +∞, the result is +0.
- If abs(x)<1 and y is −∞, the result is +∞.
- If x is +∞ and y>0, the result is +∞.
- If x is +∞ and y<0, the result is +0.
- If x is −∞ and y>0 and y is an odd integer, the result is −∞.
- If x is −∞ and y>0 and y is not an odd integer, the result is +∞.
- If x is −∞ and y<0 and y is an odd integer, the result is −0.
- If x is −∞ and y<0 and y is not an odd integer, the result is +0.
- If x is +0 and y>0, the result is +0.
- If x is +0 and y<0, the result is +∞.
- If x is −0 and y>0 and y is an odd integer, the result is −0.
- If x is −0 and y>0 and y is not an odd integer, the result is +0.
- If x is −0 and y<0 and y is an odd integer, the result is −∞.
- If x is −0 and y<0 and y is not an odd integer, the result is +∞.
- If x<0 and x is finite and y is finite and y is not an integer, the result is NaN.
What is interesting is that for any value of x the returned value is 1. Can we find any value for x for what Math.pow(x, 0) returns a value that is NOT 1?
I tried the following in the NodeJS shell, but I guess it's the same result in the browser console:
> Math.pow(undefined, 0)
1
> Math.pow(Date(), 0)
1
> Math.pow("asd", 0)
1
> Math.pow(function () {}, 0)
1
> Math.pow(function () { return 3}, 0)
1
> Math.pow([], 0)
1
> Math.pow(null, 0)
1
Maybe we find a JS trick that does this, like in the x === x // false (where isNaN(x) === false) case.
Just to clarify: y will be always 0. Only x is changing.