Created
September 15, 2021 23:29
-
-
Save alex-cory/c50176279e32d6c329411eaa43c6be1c to your computer and use it in GitHub Desktop.
isObject to test if a variable is actually only an Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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