Lodash _.isNull() method

Beginner
⏱️ 5 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.isNull(value) maps to strict value === null.
  • Why undefined, void 0, and typical falsy values return false.
  • When to prefer _.isNull over _.isNil or loose == null.
  • How null prototypes differ from the null primitive.

Prerequisites

You understand null is an intentional placeholder while undefined usually means “never assigned.”

  • You know strict equality === does not coerce types.
  • Try-it labs load lodash from the CDN.

Overview

Use _.isNull when APIs deliberately signal “cleared” via null but still distinguish missing keys (undefined)—database drivers and GraphQL responses frequently encode that split.

Strict primitive

Matches exactly one value: JavaScript null.

Undefined stays out

Unlike == null, undefined never counts.

Readable intent

Self-documenting guard versus loose equality tricks.

Syntax

javascript
_.isNull(value)
  • value: any value to test.
  • Returns: true if value is strictly null; otherwise false.
1

Literal null only

Lodash docs highlight void 0 (undefined) returning false.

javascript
import isNull from "lodash/isNull";

console.log(
  "literalNull: " + isNull(null) + "\n" +       // true
  "undef: " + isNull(undefined)               // false
);
Try it Yourself
2

void 0 and numeric zero

void 0 yields undefined—still not null; zero remains a real value.

javascript
import isNull from "lodash/isNull";

console.log(
  "void0: " + isNull(void 0) + "\n" + // false (lodash docs)
  "zero: " + isNull(0)               // false
);
Try it Yourself
3

_.isNull versus _.isNil

_.isNil groups null and undefined; _.isNull singles out explicit null.

javascript
import isNull from "lodash/isNull";
import isNil from "lodash/isNil";

console.log(
  "isNullUndef: " + isNull(undefined) + "\n" + // false
  "isNilUndef: " + isNil(undefined)          // true
);
Try it Yourself

📋 _.isNull vs related checks

API / patternBehavior
_.isNull(x)true only when x === null.
_.isNil(x)true for null or undefined.
x == nullSame truth set as _.isNil—not _.isNull.
x === undefinedIgnores explicit null assignments entirely.

Pitfalls to avoid

JSON

Missing versus null fields

JSON often drops absent keys—parsed objects expose undefined, not null, unless the payload literally contains null.

APIs

Driver defaults

Database drivers may coerce SQL NULL differently—verify whether you receive null or another sentinel.

Naming

“Null object” patterns

Placeholder objects are still objects—only the primitive null passes this helper.

❓ FAQ

No. Only the null primitive matches—undefined is a separate missing sentinel.
Use _.isNull when only explicit null matters; use _.isNil when either null or undefined should trigger the same branch.
Yes. Loose equality groups null and undefined; strict _.isNull excludes undefined.
No—that creates an ordinary object with a null prototype—the value is still an object, not the null primitive.

Summary

  • Purpose: detect the explicit null primitive and nothing else.
  • Remember: pair with _.isUndefined or _.isNil when both absent states matter.
  • Next: explore more on Lodash _.isNumber().
Did you know?

_.isNull(value) is exactly value === null—the shortest possible predicate when you intentionally distinguish null from undefined.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful