On This Page
Types Utilities
The Types utilities provide a set of functions for checking and manipulating data types in JavaScript. These functions help in writing more robust and type-safe code.
Functions
isObject
Checks if the given value is an object.
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is an object, false otherwise.
Example
isPlainObject
Checks if the given value is a plain JavaScript object (created using object literal notation or Object.create(null)).
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is a plain object, false otherwise.
Example
isString
Checks if the given value is a string.
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is a string, false otherwise.
Example
isBoolean
Checks if the given value is a boolean.
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is a boolean, false otherwise.
Example
isNumber
Checks if the given value is a number.
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is a number, false otherwise.
Example
isArray
Checks if the given value is an array.
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is an array, false otherwise.
Example
isBinary
Checks if the given value is a binary (Uint8Array).
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is a binary, false otherwise.
Example
isFunction
Checks if the given value is a function.
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is a function, false otherwise.
Example
isPromise
Checks if the given value is a Promise.
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is a Promise, false otherwise.
Example
isArguments
Checks if the given value is an arguments object.
Parameters
Name | Type | Description |
---|---|---|
obj | any | Any value to check |
Returns
boolean
- True if the value is an arguments object, false otherwise.
Example
isDOM
Checks if the given value is a DOM element.
Parameters
Name | Type | Description |
---|---|---|
element | any | Any value to check |
Returns
boolean
- True if the value is a DOM element, false otherwise.
Example
isNode
Checks if the given value is a DOM node.
Parameters
Name | Type | Description |
---|---|---|
el | any | Any value to check |
Returns
boolean
- True if the value is a DOM node, false otherwise.
Example
isEmpty
Checks if the given value is empty’ish (null, undefined, empty string, empty array, or empty object).
This is useful in scenarios where you want to treat any general empty value as non existent.
Parameters
Name | Type | Description |
---|---|---|
x | any | Any value to check |
Returns
boolean
- True if the value is empty, false otherwise.
Example
isClassInstance
Checks if the given object is an instance of a custom class (not a built-in object).
Built-in Types Exclusion This helper is specifically for determining whether a variable is an instance of a custom class. It will return
false
for built-in types like Object, Array, Date, etc., focusing on identifying instances of custom classes.
Parameters
Name | Type | Description |
---|---|---|
obj | any | The object to check |
Returns
boolean
- True if the object is an instance of a custom class, false otherwise.