or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--is-nil

The lodash method isNil exported as a Node.js module for checking null or undefined values

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.isnil@4.0.x

To install, run

npx @tessl/cli install tessl/npm-lodash--is-nil@4.0.0

index.mddocs/

lodash.isnil

lodash.isnil is a standalone Node.js module that provides the lodash method isNil for checking if a value is null or undefined (nullish values). This modularized approach allows developers to use just this specific utility without importing the entire lodash library, making it ideal for applications focused on bundle size optimization.

Package Information

  • Package Name: lodash.isnil
  • Package Type: npm
  • Language: JavaScript (ES5 compatible)
  • Installation: npm install lodash.isnil

Core Imports

var isNil = require('lodash.isnil');

For ES6 modules (with transpilation):

import isNil from 'lodash.isnil';

Basic Usage

var isNil = require('lodash.isnil');

// Check for null or undefined values
console.log(isNil(null));      // => true
console.log(isNil(undefined)); // => true
console.log(isNil(void 0));    // => true

// All other values return false
console.log(isNil(NaN));       // => false
console.log(isNil(''));        // => false
console.log(isNil(0));         // => false
console.log(isNil(false));     // => false
console.log(isNil([]));        // => false
console.log(isNil({}));        // => false

Capabilities

Nullish Value Checking

The isNil function provides reliable checking for nullish values (null or undefined) across different JavaScript environments.

/**
 * Checks if value is null or undefined.
 *
 * @param {*} value The value to check.
 * @returns {boolean} Returns true if value is nullish, else false.
 */
function isNil(value);

Implementation Details:

  • Uses loose equality check: value == null
  • Catches both null and undefined values with a single comparison
  • More reliable than strict equality checks in some edge cases
  • Compatible with all JavaScript environments (ES5+)

Usage Examples:

var isNil = require('lodash.isnil');

// Basic nullish checking
if (isNil(someVariable)) {
  console.log('Variable is null or undefined');
}

// Function parameter validation
function processData(data) {
  if (isNil(data)) {
    throw new Error('Data parameter is required');
  }
  // Process data...
}

// Array filtering
var values = [1, null, 'hello', undefined, 0, ''];
var nonNullish = values.filter(function(value) {
  return !isNil(value);
});
// Result: [1, 'hello', 0, '']

// Object property checking
var user = { name: 'John', age: null, email: undefined };
Object.keys(user).forEach(function(key) {
  if (isNil(user[key])) {
    console.log(key + ' has no value');
  }
});

Comparison with Native JavaScript:

var isNil = require('lodash.isnil');

var value = null;

// lodash.isnil approach (recommended)
isNil(value);           // => true

// Native JavaScript alternatives
value == null;          // => true (same as isNil implementation)
value === null;         // => true (only for null, not undefined)
value === undefined;    // => false (only for undefined, not null)
typeof value === 'undefined' || value === null; // => true (verbose)

Error Handling:

The isNil function never throws errors and can safely handle any input type, including:

  • Primitive values (strings, numbers, booleans)
  • Objects and arrays
  • Functions
  • Symbols (in ES6+ environments)
  • Exotic objects and host objects