Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 589 Bytes

obtain-undefined-value-with-the-void-operator.md

File metadata and controls

24 lines (19 loc) · 589 Bytes

Obtain Undefined Value With The Void Operator

The void operator takes any expression, evaluates it, and then results in the undefined value. A common use of the void operator is to get the primitive undefined value in a consistent way.

> void(0);
undefined

This is handy for instances where you need to check if a value is undefined:

function doSomething({ arg }) {
  if (arg === void 0) {
    throw new Error("arg is undefined 😱");
  }

  // ...
};