Ondra Žižka Ondra Žižka - 1 year ago 189
TypeScript Question

JavaScript: what does "void 0" mean?

TypeScript transpiles certain code into this:

Animal.prototype.move = function (distanceInMeters) {
if (distanceInMeters === void 0) { distanceInMeters = 0; }
...


What's
void 0
? Is that the same trick as used for links
void(0)
? Why is not
undefined
used instead?

Answer Source

The void operator always evaluates as the undefined value.

The undefined variable, which defaults to holding the undefined value, can be overwritten.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download