JS&TS
May 9, 2024

Check for object in JS

There we will talk about how to check whether is it object or not.

JavaScript

Usually in JS you slight not possiable to check for object through typeof because of null will be detected as an object type, so that means we have to check for null and for object as well.

function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

Summary:

If you want to check for exact object's type you will have to check for object and for null oparator as well.