Are anonymous functions the same as function expressions?

Hi, I would like to know if JavaScript anonymous functions are pretty much the same as JavaScript Function Expressions. To me, they look so much the same. Thank you for your comment.

Ex.
const rocketToMars = function () {
return ‘Boom!’ ;
}

https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/lessons/functions/exercises/function-expressions

@crispy2013

An anonymous function lacks a name. For example:

function sayMyName() {
  console.log('sayMyName is the name of this function. It is not anonymous.')
}

const sayMyName = function() {
  console.log('sayMyName is the name of the variable holding this function. The function is anonymous.')
}
1 Like

Thanks for getting back. I get your part about the lacking of a name for anonymous function.

I actually get the example from the Codecademy cheatsheet. To me, the anonymous function is identical to the function expressions BUT not the same as function declaration. Can I say an anonymous function is basically the one way of using the function expressions? Am I correct to make this statement? Thanks.

@crispy2013

I guess so…but you seem to be getting hung up on the term ‘Anonymous’ as if its implications are further-reaching. It’s explained in the images you included above… “Anonymous functions in Javascript do not have a name property”…"(Function expressions) can be anonymous (i.e. not have a name property) and/or assigned to a variable."

1 Like

OK, thanks for sharing your thoughts

1 Like