Files
30-seconds-of-code/snippets/isObjectLike.md
Isabelle Viktoria Maciohsek 8bf67754ce Make expertise a field
2022-03-01 20:21:45 +02:00

23 lines
481 B
Markdown

---
title: Value is object-like
tags: type,object
expertise: beginner
firstSeen: 2018-01-23T19:30:03+02:00
lastUpdated: 2020-09-15T16:28:04+03:00
---
Checks if a value is object-like.
- Check if the provided value is not `null` and its `typeof` is equal to `'object'`.
```js
const isObjectLike = val => val !== null && typeof val === 'object';
```
```js
isObjectLike({}); // true
isObjectLike([1, 2, 3]); // true
isObjectLike(x => x); // false
isObjectLike(null); // false
```