Lodash isFunction Browser and Runtime Compatibility

This article evaluates the reliability and environmental support of Lodash's _.isFunction method across various JavaScript runtimes. It covers modern browsers, legacy environments, server-side platforms, and multi-realm execution contexts like iframes. By examining how Lodash handles type-checking internally, this guide clarifies where developers can depend on this utility without encountering typical edge cases associated with standard JavaScript evaluation.

How Lodash Implements _.isFunction

In vanilla JavaScript, using typeof value === 'function' or value instanceof Function can lead to false positives, false negatives, or runtime crashes in specific environments. For example, instanceof Function fails across different execution realms (such as iframes) because each realm possesses its own prototype chain and global Function constructor.

Lodash implements _.isFunction to normalize these discrepancies. Under the hood, it primarily verifies that the target value is an object and checks its internal [[Class]] tag via Object.prototype.toString.call(value) === '[object Function]' (along with checks for [object AsyncFunction], [object GeneratorFunction], and [object Proxy]). This ensures that the detection mechanism remains robust regardless of where the function was instantiated.

Supported Environments and Reliability

Modern Web Browsers

_.isFunction is completely reliable across all modern web browser engines:

In these environments, _.isFunction accurately identifies standard function declarations, function expressions, ES6 arrow functions, async functions, and generator functions without any inconsistencies.

Multi-Realm Contexts (iframes and Popups)

One of the primary benefits of _.isFunction is its complete reliability within multi-window and iframe architectures. In these setups, passing a callback function from a child iframe to a parent window will cause standard instanceof Function evaluations to return false. Because Lodash inspects the object's internal string tag rather than constructor inheritance, _.isFunction correctly identifies functions passed across different windows and frames.

Server-Side Runtimes

Lodash fully supports all mainstream JavaScript server environments:

Server-side execution avoids DOM-related type quirks, making the check fast and deterministic.

Web Workers and Service Workers

_.isFunction is reliable inside Web Workers, Shared Workers, and Service Workers. Since workers operate within isolated threads without a DOM, functions created in these scopes behave identically to standard ECMAScript functions and are correctly detected.

Legacy Environments

Lodash was heavily optimized to overcome quirks found in historical and legacy platforms:

Summary of Function Types Handled

Across all supported environments, _.isFunction reliably returns true for:

It consistently returns false for objects, arrays, regular expressions, primitives, null, and undefined across every runtime.