diff --git a/README.md b/README.md index cfc3c1a51..feeef16c7 100644 --- a/README.md +++ b/README.md @@ -8677,12 +8677,10 @@ isPlainObject(new Map()); // false Returns a boolean determining if the passed value is primitive or not. -Use `Array.prototype.includes()` on an array of type strings which are not primitive, -supplying the type using `typeof`. -Since `typeof null` evaluates to `'object'`, it needs to be directly compared. +Create an object from `val` and compare it with `val` to determine if the passed value is primitive (i.e. not equal to the created object). ```js -const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null; +const isPrimitive = val => Object(val) !== val; ```
diff --git a/docs/type.html b/docs/type.html index cbba0faf8..37a12f323 100644 --- a/docs/type.html +++ b/docs/type.html @@ -152,7 +152,7 @@

isPlainObject

Checks if the provided value is an object created by the Object constructor.

Check if the provided value is truthy, use typeof to check if it is an object and Object.constructor to make sure the constructor is equal to Object.

const isPlainObject = val => !!val && typeof val === 'object' && val.constructor === Object;
 
isPlainObject({ a: 1 }); // true
 isPlainObject(new Map()); // false
-

isPrimitive

Returns a boolean determining if the passed value is primitive or not.

Use Array.prototype.includes() on an array of type strings which are not primitive, supplying the type using typeof. Since typeof null evaluates to 'object', it needs to be directly compared.

const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null;
+

isPrimitive

Returns a boolean determining if the passed value is primitive or not.

Create an object from val and compare it with val to determine if the passed value is primitive (i.e. not equal to the created object).

const isPrimitive = val => Object(val) !== val;
 
isPrimitive(null); // true
 isPrimitive(50); // true
 isPrimitive('Hello!'); // true