ES6 - Use Arrow Functions to Write Concise Anonymous Functions

Tell us what’s happening:
I don’t understand
what is the necessity of passing a function as an argument??

And also How to see this return value in the console??

Your code so far

const myFunc = function() {
  const myVar = "value";
  return myVar;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: ES6 - Use Arrow Functions to Write Concise Anonymous Functions

Link to the challenge:

Sometimes you may want to use some function inside other function, like in example below.

const add = (num1, num2) => {
  return num1 + num2;
}

const subtract = (num1, num2) => {
  return num1 - num2;
}

const myFunc = (num1, num2, addOrSubtract) => {
  return addOrSubtract(num1, num2);
}

console.log(myFunc(3, 5, add))//8
console.log(myFunc(3, 5, subtract))//-2

just log it out like below

const myFunc = function() {
  const myVar = "value";
  return myVar;
}

console.log(myFunc())
1 Like

Understood clearly
Thanks a lot !!