Skip to content

Instantly share code, notes, and snippets.

@alex-cory
Created September 15, 2021 23:29
Show Gist options
  • Save alex-cory/c50176279e32d6c329411eaa43c6be1c to your computer and use it in GitHub Desktop.
Save alex-cory/c50176279e32d6c329411eaa43c6be1c to your computer and use it in GitHub Desktop.
isObject to test if a variable is actually only an Object
const isObject = v => Object.prototype.toString.call(v) === '[object Object]'
Object.entries({
'{}': {},
Set: new Set([1,2,3,4]),
Date: new Date(),
null: null,
undefined: undefined,
string: 'string',
NaN: NaN,
func: () => {},
Function: Function,
'3': 3,
}).reduce((acc, [k, v]) => {
acc[k] = isObject(v)
return acc
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment