var x= 1;
Number.prototype.test = function () { return this };
x.test() === x.test() // false
Why does the === test return false?
Because this will be a Number object, not the original primitive number value, and comparing two equally created objects will always return false:
{"test":"Hello"} === {"test":"Hello"} // false
// Check the typeof your vars
var x= 1;
Number.prototype.test = function () { return this };
x.test() === x.test() // false
alert("x is a "+typeof(x)+", x.test() is an "+typeof(x.test()));
If you're looking for a fix, cast this to a number
var x= 1;
Number.prototype.test = function () { return +this };
x.test() === x.test() // TRUE!
alert("x is a "+typeof(x)+", x.test() is also a "+typeof(x.test()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With