class Example {
constructor() {}
}
const entries = [
new Example(),
{},
new Object(),
[],
new Array(),
42,
'Hello World',
true,
null,
undefined
];
entries.forEach((entry, index) => {
if (entry instanceof Example) {
console.log(`is example - ${index}`);
} else if (entry instanceof Array) {
console.log(`is array - ${index}`);
} else if (entry instanceof Object) {
console.log(`is object - ${index}`);
} else {
console.log(`is ${typeof entry} - ${index}`)
}
});
/*
is example - 0
is object - 1
is object - 2
is array - 3
is array - 4
is number - 5
is string - 6
is boolean - 7
is object - 8
is undefined - 9
*/