Exercise 13: Check if Object is Empty

Problem Statement

Function `isEmpty(obj)` banao jo check kare ki object empty hai ya nahi. Example: isEmpty({}) => true, isEmpty({a: 1}) => false

Sample Output:

isEmpty({}) => true
isEmpty({a: 1}) => false
isEmpty(null) => true

Solution

const isEmpty = (obj) => {
  if (obj == null || typeof obj !== "object") return true;
  return Object.keys(obj).length === 0;
};

Explanation

Overall Goal:

  • Object empty hai ya nahi check karna.

Real world:

  • Validation: empty object checks.
  • Data processing: empty data handling.