FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Is Empty

15mins

Implement a function isEmpty(value) that checks whether a value is empty.

The function should:

  • Return true for:
    • empty objects: {}
    • empty arrays: []
    • empty strings: ''
    • empty Maps and Sets
  • Return false for non-empty objects, arrays, strings, Maps, or Sets.
  • Treat null and undefined as empty.
  • Return false for other non-collection types.

Example

isEmpty({}); // true isEmpty([]); // true isEmpty(''); // true isEmpty(new Map()); // true isEmpty(new Set()); // true isEmpty({a:1}); // false isEmpty([1]); // false isEmpty('foo'); // false

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests