I'm sorry if this is a duplicate, I have read a few posts asking this question but I haven't found a satisfying answer. I am new to JS, I have worked with C and Java. I recently learned about function expressions which, as far as I understand it, are anonymous function declarations that are assigned to some const variable. I don't see what the motivation behind this is/what the possible use of this is/ how could this ever do something you couldn't just do with a function declaration. for example
const example = function (input){
return 'Am I useless?:' + input;
}
console.log(example('Idk'));
Like this is just like calling a declared function with the same variable, but instead I'm using this variable name (example
), which also makes the anonymous
function seem pseudo anonymous since it does have a name it can be reference by.
I don't see when this would ever preferable over just a function declaration, yet the CodeCademy course I'm taking repeatedly uses the function expression thing, so I must be missing something.
I really appreciate the help/clarification.