High order function First class citizens in JavaScript - IndianTechnoEra
Latest update Android YouTube

High order function First class citizens in JavaScript

 

High order function that can be assigned with any variable or function and can be return 

First class citizens function is that function that can return to another function


Example 1: 

const maths = {
  add: (a, b) => {

    return `${a}+${b} = ${a + b}`
  },
  product: (a, b) => {
    return `${a}*${b} = ${a * b}`
  },
  sum_and_product:(a,b)=>{
    return `${maths.add(a,b)}  ${maths.product(a,b)}`
  }
}

console.log(maths.add(78,4))      //78+4 = 82
console.log(maths.product(78,4))  //78*4 = 312
console.log(maths.sum_and_product(11,12)) //11+12 = 23  11*12 = 132

// here add is an arrow function that has been assigned with maths so add will be higher order function and sum_and_Product is returning function so it will be first class citizen

Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.