Skip to content

Instantly share code, notes, and snippets.

Last active July 17, 2020 07:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
@func complement
confirm that the supplied value is not an obj
@param {*} v expect anything but an obj
@return {boolean}
export const isNotObj = v => !isObj(v);
is the value of type obj?
an empty obj is also true
may not work in IE 11
@param {{}} o obj expected
@return {boolean}
export const isObj = o => isNotNil(o) && o.constructor === Object;
const aTrue = [{}, { id: 166 },
(() => ({}))(), //a func that returns an empty obj
new Object(),
Object.fromEntries([]), //cast a 2D arr of key/value pairs into an obj
Object.fromEntries([ Map()]), //cast a Map to an obj
JSON.parse("{}"), //deserialize a string into an obj
const aFalse = [null, undefined, "{}", [{}], () => { }, [], [1, 2, 3], "", Object,
new Array(), new Function(), new String(), new Number(), new Boolean(),
new RegExp(/_/), , new Date(), Infinity, BigInt, Map, new Map(),
new Map(Object.entries({ foo: "bar" })),
new Map([[1, "uno"], [2, "dos"]]),
logForeachParam(isObj, aTrue);
logForeachParam(isObj, aFalse);
timeInLoop("isObj", 1e9, //1.737 for 1e9
() => {
logForeachParam sourcecode at:
isNil and isNotNil sourcecode at:
timeInLoop sourcecode at:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment