VOOZH about

URL: https://www.geeksforgeeks.org/javascript/underscore-js-_-defaults-function/

⇱ Underscore.js _.defaults() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Underscore.js _.defaults() Function

Last Updated : 12 Jul, 2025

Underscore.js_.defaults() function returns the object after filling in its undefined properties with the first value present in the following list of default objects.

Syntax:

_.defaults(object, *defaults);

Parameters:

  • object: This parameter holds the value of an object.
  • defaults: It is an optional parameter. It contains the [key, value] pair of an object.

Return Value:

It returns the object after filling in its undefined properties with the first value present in the following list of default objects.

Example 1: The below code example implements the _.defaults() function in underscore.js.

Output:

👁 Image

Example 2: This is another implementation of the _.defaults() function.

Output:

👁 Image
Comment