Function in JavaScript  

Function in JavaScript Function is a block of law that is designed to perform a particular task is called JavaScript Function

Type of function in JavaScript 

  • Named Function 
  • Anonymous Function 
  • Immediately invoked function expressions

Named Function

Named function is the function that we define it in the law and also call it. Whenever we need it by representing its name and passing some argument to it illustration


function oddorEven(number){


             return "Number is even"


         else {

                  return "Number is odd"


console.log (oddorEven (4)) // Number is even


Anonymous Function 

The anonymous function does not have a name. They need to be tied to commodity variables or events to run an illustration


let anonymousFun = function () {  

    console.log (‘this is an anonymous function');  // this is an anonymous function'


anonymousFun ();  

Immediately invoked function expression (IIFE)

Invoked function expression runs as soon as the cyber surfer encounters it. The benefit of this function is that it runs incontinently where it’s located in the law and produces a direct affair illustration


let invoked = (function (){

    let name="Immediately invoked function expression"

    return console.log (name) // Immediately invoked function expression


Leave a Reply