Q:

Writing anonymous function is giving error

I am trying to compare 'named function' to 'anonymous function' but in a simple propgram I am getting error. I am doing everything right, don't know why error is coming. Can someone help? 

<html>
<head></head>
<body>
<script>

//named Fn
function alpha(){
  alert('hi');
}

//Anonymous Fn
function(){
  alert('hello');
}

//IIFE
(function (){
  alert('good day');
})();

alpha(); 

</script>
</body>
</html>

I expect 'good day' and 'hi' to be alerted but instead getting error. 

Note: I read anonymous function is one without a name so wrote the
  second function without name. Please, someone paste correct snippet as
  I don't know why this is wrong 

 function(){ <------------------- A function without name.

A:

You can't really declare an anonymous function. You need to use it when something calls for it. you have:
function(){
  alert('hello');
}

That's going to always throw an error since you haven't named it. If you attached it to something where an anonymous function is appropriate you'd be fine. such as:
setTimeout(function(){
  alert('hello');
}, 500);

So you're modified and working code snippet would look like this:

//named Fn
function alpha(){
  alert('hi');
}

//Anonymous Fn
setTimeout(function(){
  alert('hello');
}, 500);

//IIFE
(function (){
  alert('good day');
})();

alpha(); 

You could also just make it an IIFE like this:

//named Fn
function alpha(){
  alert('hi');
}

//Anonymous Fn
(function(){
  alert('hello');
})();

//IIFE
(function (){
  alert('good day');
})();

alpha();

