Thursday, September 18, 2025
HomeLanguagesJavascriptUnderscore.js _.flip2() Method

Underscore.js _.flip2() Method

The _.flip2() method returns a function that works identically to given function but accepts the first two arguments in reverse order. The order of all rest arguments remains the same.

Syntax:

_.flip2( function );

Parameters: This method takes a function that takes some arguments.

Return Value: This method returns a function.

Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed. 

underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1:

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
function gfgFunc(a, b, c) {
    return "Value of a is " +
    a + " and Value of b is " + 
    b + " and Value of c is " + c;
}
  
var abc = _.flip2(gfgFunc);
  
console.log(abc(1, 2, 3));


Output:

Value of a is 2 and Value of b is 1 and Value of c is 3

Example 2: 

Javascript




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
function gfgFunc(a, b) {
    return b + " is " + a;
}
  
var gfg = _.flip2(gfgFunc);
  
console.log(gfg("neveropen",+
   "Computer Science Portal for Geeks"));


Output:

neveropen is Computer Science Portal for Geeks
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6660 POSTS0 COMMENTS
Nicole Veronica
11834 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7051 POSTS0 COMMENTS
Thapelo Manthata
6735 POSTS0 COMMENTS
Umr Jansen
6741 POSTS0 COMMENTS