๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—ถ๐—ป ๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜

Functions help you group code into reusable blocks. You need to know the different types to write better code.

Here are the main types of functions:

โ€ข Named Functions These use a specific name. function greet() { return "Hello!"; }

โ€ข Anonymous Functions These do not have a name. const greet = function() { return "Hi!"; };

โ€ข Function Expressions You store a function inside a variable. const add = function(a, b) { return a + b; };

โ€ข Arrow Functions A shorter syntax introduced in ES6. const square = n => n * n;

โ€ข IIFE (Immediately Invoked Function Expression) This runs as soon as you define it. (function () { console.log("Runs now!"); })();

โ€ข Async Functions These handle asynchronous operations. async function fetchData() { return "Data ready!"; }

โ€ข Pure Functions These return the same result for the same inputs and have no side effects. function pureAdd(a, b) { return a + b; }

Other important types include:

Mastering these will improve your coding skills.

Source: https://www.geeksforgeeks.org/javascript/functions-in-javascript/ Full post: https://dev.to/madhanraj/functions-in-javascript-3k17