- Named Function
- Anonymous Function
- Immediately Invoked function expression.
Syntax:
function function_Name(param1, param2){
function body
}
function_Name();
Syntax:
var fun = function(param) {
do something here (Body of the function)
}
fun(param);
Let's understand with an example.
<script type ="text/javascript">
var anonymousFun = function(param1, param2) {
alert(param1 + " Good morning " + param2);
}
anonymousFun("Hello", "anonymous function");
</script>
Add the above code to a web page an run the application then output would be :
Hello Good morning anonymous function
<script type ="text/javascript">
var msg = (function(){
var name= "Dal Chand";
return name;
})();
</script>
Outpou: Dal Chand






























