What is void 0?

I learn Javascript by reading some kind of 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 feature has been added to Object.prototype.
I don't quite get void 0at the end of the triple expression. Can someone explain this to me?

Thank.

+4
source share
2 answers

The void operator is often used simply to get a primitive value undefined, usually using "void (0)" (which is equivalent to "void 0"). In these cases, the global variable undefined can be used instead (if it has not been assigned to a value other than the default).

undefined: :

_this[i] !== undefined;

Jsfiddle Demo

+5

void 0 - undefined . undefined, void

+2

Source: https://habr.com/ru/post/1532939/


All Articles