VOOZH about

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

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


  • Courses
  • Tutorials
  • Interview Prep

Underscore.js _.noConflict() Function

Last Updated : 28 Oct, 2021

Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. 
The _.noConflict() function is used to create a reference of the global underscore object "_" to another variable.

Note: It is very necessary to link the underscore CDN before going and using underscore functions in the browser. When linking the underscore.js CDN The "_" is attached to the browser as a global variable.

Syntax:

_.noConflict()

Parameters: This function does not accept any parameter.

Return Value: It returns the reference to the global underscore variable.

Example 1: When noConflict() function is not used and using "underscore" variable.

Output:

  • When button is not clicked: 
     
👁 Image
  • When button is clicked: 
     
👁 Image

Example 2: When noConflict() function is used.

Output:

  • When button is not clicked: 
     
👁 Image
  • When button is clicked: 
     
👁 Image
Comment