diff --git a/README.md b/README.md index b2adc64..d2311c4 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_843 TILs and counting..._ +_844 TILs and counting..._ --- @@ -306,6 +306,7 @@ _843 TILs and counting..._ - [New Dates Can Take Out Of Bounds Values](javascript/new-dates-can-take-out-of-bounds-values.md) - [Numbers Are Empty](javascript/numbers-are-empty.md) - [Object Initialization With Shorthand Property Names](javascript/object-initialization-with-shorthand-property-names.md) +- [Obtain Undefined Value With The Void Operator](javascript/obtain-undefined-value-with-the-void-operator.md) - [Random Cannot Be Seeded](javascript/random-cannot-be-seeded.md) - [Reach Into An Object For Nested Data With Get](javascript/reach-into-an-object-for-nested-data-with-get.md) - [Render An Array Of Elements With React 16](javascript/render-an-array-of-elements-with-react-16.md) diff --git a/javascript/obtain-undefined-value-with-the-void-operator.md b/javascript/obtain-undefined-value-with-the-void-operator.md new file mode 100644 index 0000000..7bc1553 --- /dev/null +++ b/javascript/obtain-undefined-value-with-the-void-operator.md @@ -0,0 +1,24 @@ +# Obtain Undefined Value With The Void Operator + +The [`void` +operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void) +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. + +```javascript +> void(0); +undefined +``` + +This is handy for instances where you need to check if a value is `undefined`: + +```javascript +function doSomething({ arg }) { + if (arg === void 0) { + throw new Error("arg is undefined 😱"); + } + + // ... +}; +```