Returns true
if the given object
is a primitive type. Otherwise, returnsfalse
.
const util = require('util');
util.isPrimitive(5);
// Returns: true
util.isPrimitive('foo');
// Returns: true
util.isPrimitive(false);
// Returns: true
util.isPrimitive(null);
// Returns: true
util.isPrimitive(undefined);
// Returns: true
util.isPrimitive({});
// Returns: false
util.isPrimitive(() => {});
// Returns: false
util.isPrimitive(/^$/);
// Returns: false
util.isPrimitive(new Date());
// Returns: false
Since v4.0.0 - Use (typeof value !== 'object' && typeof value !== 'function') || value === null
instead.
Generated using TypeDoc
Returns
true
if the givenobject
is a primitive type. Otherwise, returnsfalse
.Deprecated
Since v4.0.0 - Use
(typeof value !== 'object' && typeof value !== 'function') || value === null
instead.