Because it thiswill be a Number object, not the initial value of a primitive number, and a comparison of two equally created objects will always return false:
{"test":"Hello"} === {"test":"Hello"}
var x= 1;
Number.prototype.test = function () { return this };
x.test() === x.test()
alert("x is a "+typeof(x)+", x.test() is an "+typeof(x.test()));
If you are looking for a fix, add thisto the number
var x= 1;
Number.prototype.test = function () { return +this };
x.test() === x.test()
alert("x is a "+typeof(x)+", x.test() is also a "+typeof(x.test()));
source
share