I have a scenario where function only gets one argument which could be either object
or null
. As both object and null has type of object
. How can I use if statement on them to differentiate? If I use typeof
then both object and null will return object.
UPDATE
function func (par) {
if (par === null) {
console.log(null);
}
if (typeof par === "object") {
console.log(object);
}
}
func({key1: 'val1', key2: 'val2'});
func(null);