What is Underscore.js ?

Overview

Underscore.js is a popular JavaScript library that contains multiple utility and helper functions. Underscore.js can be used directly inside a browser and also with Node.js.

Note: To learn more about Underscore.js, click here.

Underscore.js includes multiple helper functions for the following:

  • Arrays
  • Functions
  • Objects
  • Collections
  • Equality testing
  • Function binding

Note: Underscore.js is licensed under the MIT License. You can find the repo of Underscore.js here.

Example

The code below demonstrates how to use Underscore.js.

Console
Using the Underscore.js library

Explanation

  • Line 8: We include the Underscore.js library file from the CDN server.
  • Line 10: We create an array, numbers.
  • Line 12: We use the first method of the Underscore.js library to get the first element of the array. We get 1 as a result.
  • Line 13: We use the last method of the Underscore.js library to get the last element of the array. We get 6 as a result.
  • Line 14: We use the min method of the Underscore.js library to get the minimum value element of the array. We get 1 as a result.
  • Line 15: We use the shuffle method of the Underscore.js library to get a shuffled copy of the numbers array.

Note: We can see all the functions available in Underscore.js here.

Free Resources