Add some examples
From the old test suite
This commit is contained in:
@@ -5,14 +5,14 @@ tags: type,beginner
|
||||
|
||||
Returns the native type of a value.
|
||||
|
||||
Return `"undefined"` or `"null"` if the value is `undefined` or `null`.
|
||||
Otherwise, use `Object.prototype.constructor.name` to get the name of the constructor, `String.prototype.toLowerCase()` to return it in lowercase.
|
||||
Return `'undefined'` or `'null'` if the value is `undefined` or `null`.
|
||||
Otherwise, use `Object.prototype.constructor.name` to get the name of the constructor.
|
||||
|
||||
```js
|
||||
const getType = v =>
|
||||
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
|
||||
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name;
|
||||
```
|
||||
|
||||
```js
|
||||
getType(new Set([1, 2, 3])); // 'set'
|
||||
getType(new Set([1, 2, 3])); // 'Set'
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user