How Lodash isObjectLike Handles Functions

The Lodash library provides several utility functions to inspect data types, among which _.isObjectLike is specifically designed to identify object-like values while excluding primitives, null, and executable functions. This article examines the explicit exclusion rules _.isObjectLike applies to function references, details the underlying JavaScript type checks responsible for this behavior, and contrasts the method with _.isObject.

The Core Exclusion Rule: The typeof Evaluation

At its core, _.isObjectLike checks whether a value is not null and has a typeof evaluation strictly equal to "object". The exact internal implementation in Lodash is:

function isObjectLike(value) {
  return typeof value === 'object' && value !== null;
}

Because of this strict definition, any value that yields a typeof result other than "object" is immediately rejected. In JavaScript, all executable function references return "function" when evaluated by the typeof operator. Consequently, functions fail the typeof value === 'object' condition and are excluded by default.

Excluded Function Types

The typeof check applies universally across the JavaScript runtime to all variations of executable callables. As a result, _.isObjectLike returns false for all of the following:

Even though functions in JavaScript are first-class objects capable of holding properties, prototype chains, and custom methods, _.isObjectLike deliberately ignores these object characteristics in favor of the language's native "function" type tag.

Comparison: _.isObjectLike vs. _.isObject

The exclusion of function references is the defining difference between _.isObjectLike and Lodash’s standard _.isObject utility.

If an application requires checking for structural records or dictionaries while ensuring the target cannot be invoked as an executable routine, _.isObjectLike acts as a guard against passing function references.