
Types of Functions in JavaScript
1. Function Declaration This is the basic way to create a function. Example: function sayHello () { console . log ( " Hello " ); } sayHello (); Output: Hello 2. Function Expression Here, the function is stored in a variable. Example: const sayHello = function () { console . log ( " Hello " ); }; sayHello (); Output: Hello 3. Arrow Function (Lambda) Short and modern way to write functions. Example: const sayHello = () => { console . log ( " Hello " ); }; sayHello (); Output: Hello 4. Anonymous Function Function without a name. Example: const greet = function () { return " Hi there! " ; }; console . log ( greet ()); Output: Hi there! 5. Callback Function A function passed inside another function. Example: function greet ( name , fun ) { fun ( name ); } greet ( " Ram " , function ( name ) { console . log ( " Hello " + name ); }); Output: Hello Ram 6. IIFE (Immediately Invoked Function) Runs immediately after writing. Example: ( function () { console . log ( " Run now " ); })(); Output: Ru
Continue reading on Dev.to
Opens in a new tab

.png&w=1200&q=75)