3 ms·
My team checks for types, not for null. `const isString = myVar => typeof myVar !== 'string'` This is more reusable and more idiomatic in my opinion than null
by Rumudiez 8y ago
My team checks for types, not for null.
`const isString = myVar => typeof myVar !== 'string'`
This is more reusable and more idiomatic in my opinion than null/undefined checks
- styfle 8y agoThis is especially useful if you are using TypeScript (or Flow I assume) because the type checker can give you an error at compile time. After performing the runtime check, TypeScript will know that null/undefined is not possible. See this example https://goo.gl/AyoC3T https://goo.gl/AyoC3T
- jscissr 8y agoBut then you have the problem that typeof null === 'object'.
- hibbelig 8y agoShouldn't that be called `isNotString`?