I'm learning Javascript by reading some code, but this function really puzzles me.
hv:
function(i) {
var _this = this;
return isArr(_this) ? _this.indexOf(i) > -1 : _this[i] !== void 0;
}
This function is added to Object.prototype
.
I don't quite get the void 0
at the end of the ternary expression. Can someone explain it to me?
Thanks.
The void operator is often used merely to obtain the undefined primitive value, usually using “void(0)” (which is equivalent to “void 0”). In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value).
in this cases, the global variable undefined can be used instead: ie:
_this[i] !== undefined;
Jsfiddle Demo
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