javacript function meaning

Hi all. Maybe thi is a stupid quetion, but I would like to understand the difference between these two forms of writing functions in javascript:

var doStuff = function(){
  return stuff;

Open in new window


function doStuff(){
  return stuff;

Open in new window

Thank you
LVL 31
Marco GasiFreelancerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Big MontyConnect With a Mentor Senior Web Developer / CEO of Commented:
your first code snippet declares a variable and assigns the return value of the function to that variable.

the second code snippet still returns a value, but it's not storing the data in any variable. This method is commonly used when you just want execute some code and don't care about any return value
Marco GasiFreelancerAuthor Commented:
Thank you for the clear explanation.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.