Functions in JavaScript

Function ek reusable block hota hai jo code ko repeat hone se bachata hai.

Why Functions?

Types of Functions

1. Function Declaration

function greet(){
    console.log("Hello");
}

2. Function Expression

const greet = function(){
    console.log("Hello");
}

3. Arrow Function

const greet = () => {
    console.log("Hello");
}

Example

function add(a, b){
    return a + b;
}
console.log(add(5, 10));
Back