I'm trying to write a prototype for determining if a string is empty. It's really just playing with JS and prototype, nothing important. Here's my code:
String.prototype.IsEmpty = function() {
return (this === "");
}
Notice I used the ===
identity comparison instead of ==
equality. When I run the function with the above definition:
"".IsEmpty(); // false
If I chagne the definition to use ==
as:
String.prototype.IsEmpty = function() {
return (this == "");
}
The new def'n will do:
"".IsEmpty(); // true
I don't understand why ===
doesn't work since ""
is identical to ""
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