mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Numbers Are Empty as a javascript til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
|||||||
warrant a full blog post. These are mostly things I learn by pairing with
|
warrant a full blog post. These are mostly things I learn by pairing with
|
||||||
smart people at [Hashrocket](http://hashrocket.com/).
|
smart people at [Hashrocket](http://hashrocket.com/).
|
||||||
|
|
||||||
_373 TILs and counting..._
|
_374 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -130,6 +130,7 @@ _373 TILs and counting..._
|
|||||||
- [Create An Array Containing 1 To N](javascript/create-an-array-containing-1-to-n.md)
|
- [Create An Array Containing 1 To N](javascript/create-an-array-containing-1-to-n.md)
|
||||||
- [Enable ES7 Transforms With react-rails](javascript/enable-es7-transforms-with-react-rails.md)
|
- [Enable ES7 Transforms With react-rails](javascript/enable-es7-transforms-with-react-rails.md)
|
||||||
- [Immutable Remove With The Spread Operator](javascript/immutable-remove-with-the-spread-operator.md)
|
- [Immutable Remove With The Spread Operator](javascript/immutable-remove-with-the-spread-operator.md)
|
||||||
|
- [Numbers Are Empty](javascript/numbers-are-empty.md)
|
||||||
- [Object Initialization With Shorthand Property Names](javascript/object-initialization-with-shorthand-property-names.md)
|
- [Object Initialization With Shorthand Property Names](javascript/object-initialization-with-shorthand-property-names.md)
|
||||||
- [Random Cannot Be Seeded](javascript/random-cannot-be-seeded.md)
|
- [Random Cannot Be Seeded](javascript/random-cannot-be-seeded.md)
|
||||||
- [Splat Arguments To A Function](javascript/splat-arguments-to-a-function.md)
|
- [Splat Arguments To A Function](javascript/splat-arguments-to-a-function.md)
|
||||||
|
|||||||
21
javascript/numbers-are-empty.md
Normal file
21
javascript/numbers-are-empty.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Numbers Are Empty
|
||||||
|
|
||||||
|
The [`lodash`](https://lodash.com/) project comes with a ton of handy
|
||||||
|
JavaScript utilities including the
|
||||||
|
[`_.isEmpty()`](https://lodash.com/docs#isEmpty) function. This is great for
|
||||||
|
checking if Arrays, Objects, and Strings are _empty_. The following is how
|
||||||
|
this function is defined in the docs:
|
||||||
|
|
||||||
|
> Checks if value is an empty collection or object. A value is considered
|
||||||
|
> empty if it's an arguments object, array, string, or jQuery-like
|
||||||
|
> collection with a length of 0 or has no own enumerable properties.
|
||||||
|
|
||||||
|
Having not examined this definition too closely and because I primarily
|
||||||
|
write Rails code from day to day, I conflated `_.isEmpty()` with the
|
||||||
|
`#blank?` method provided by Rails' `ActiveSupport`. This holds true for the
|
||||||
|
most part, but quickly defies expectations when it comes to numbers.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
> _.isEmpty(1)
|
||||||
|
// true
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user