JavaScript: Test If a Value is Object Type ð
By Xah Lee. Date: . Last updated: .
const xah_is_obj = ((x) => {
const yy = typeof x;
return (x !== null) && (yy === "object" || yy === "function");
});
console.log(
[
{},
[],
/./,
new Date(),
function f() {},
(x) => 3,
new Set(),
new Map(),
new WeakMap(),
new WeakSet(),
function* () {},
(function* () {})(),
JSON,
Math,
Error(),
new Promise(() => {}),
].every(xah_is_obj),
);
console.log(
[null, 3, 1, Infinity, NaN, "", true, undefined, Symbol()].every((x) =>
xah_is_obj(x) === false
),
);
JavaScript Object and Inheritance