0

Both the functions below give the same output,right?So what are the uses of using an anonymous function, instead of using a properly named function such as the second one below

function foo () {
   // some work done 
}
foo();

let foo = function () {
    // some work done 
}
foo();
LMN
  • 1
  • What if you want to pass a (callback) function to another function? Do you want to always define a named function for that? – UnholySheep Oct 29 '17 at 12:57
  • In your example, the *first* one is the properly declared function, the second one is the "anonymous" function expression. – Bergi Oct 29 '17 at 13:20
  • The uses of anonymous functions are when you do something else with it (e.g. passing it as an argument) than to initialise a variable with it – Bergi Oct 29 '17 at 13:22

0 Answers0