Important Notice:

Ways of Function Declaration in JavaScript

Ways of Function Declaration in JavaScript

18 views 1 min read

Ways of Function Declaration:-

1. Simple Function / Normal Function:-

Definition

जो function सामान्य तरीके से बनाया जाता है उसे Normal Function कहते हैं।

Syntax:-

function functionName() {

// code

}

Example:-

function hello() {

console.log("Hello Students");

}

 

hello();

Output:-

Hello Students

2. Function with Parameters:-

Definition

जब function input value लेता है, उसे Parameter Function कहते हैं।

Example

function add(a, b) {

console.log(a + b);

}

add(10, 20);

Output:-

30

Explanation

a और b parameters हैं।

10 और 20 arguments हैं।

3. Function with Return Value:-

Definition

जो function कोई value वापस भेजता है उसे Return Function कहते हैं।

 

Example:-

function multiply(a, b) {

return a * b;

}

let result = multiply(5, 4);

console.log(result);

Output:-

20

4. Anonymous Function:-

Definition

जिस function का कोई नाम नहीं होता उसे Anonymous Function कहते हैं।

Example:-

let msg = function() {

console.log("Anonymous Function");

};

msg();

Output:-

Anonymous Function

5. Arrow Function:-

Definition

ES6 में introduced short syntax वाला function Arrow Function कहलाता है।

Syntax:-

const functionName = () => {

// code

}

Example:-

const greet = () => {

console.log("Welcome");

};

 

greet();

Output:-

Welcome

Related Notes