Most Developers Can't Answer This Question About Anonymous Functions 🤯

Jon Randy 🎖️ - Mar 27 '23 - - Dev Community

Given the following code:

function add(a, b) {
  return a + b
}
const add1 = function(a, b) {
  return a + b
}
const add2 = function add(a, b) {
  return a + b
}
const add3 = (a, b) => a + b
const addFunctions = []
addFunctions.push( (a, b) => a + b )
addFunctions.push(add3)
addFunctions[2] = (a, b) => a + b
Enter fullscreen mode Exit fullscreen mode

Which of the following expressions evaluate to anonymous functions:

  • a) addFunctions[2]
  • b) (a, b) => a + b
  • c) add
  • d) addFunctions[0]
  • e) add1
  • f) add2
  • g) addFunctions[1]
  • h) add3
  • i) (function (a,b) { return a + b })

Give it your best shot in the comments! 🙂


Since this post is now quite old, I've added the solution:

CLICK FOR ANSWER
The correct answer is: a, b, d, i

. . . . . . . . . . . . . . . . . . . . . . . . . . . .