30-seconds-of-code
Version:
A collection of useful JavaScript snippets.
15 lines (10 loc) • 328 B
Markdown
Returns the native type of a value.
Returns lowercased constructor name of value, `"undefined"` or `"null"` if value is `undefined` or `null`.
```js
const getType = v =>
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
```
```js
getType(new Set([1, 2, 3])); // 'set'
```