# Functions in JavaScript

Whenever we want to perform some specific operations we can use functions, because of the reusablity of these functions.

Here are the advantages of the Functions.

𝟏.𝐂𝐨𝐝𝐞 𝐑𝐞𝐮𝐬𝐚𝐛𝐥𝐢𝐭𝐲

We can call same function many time to reuse it.

𝟐. 𝐋𝐞𝐬𝐬 𝐂𝐨𝐝𝐞

Becuase of code reusablity line of code get minimum, so you have to write less code.

### 𝐒𝐲𝐧𝐭𝐚𝐱 𝐨𝐟 𝐭𝐡𝐞 𝐟𝐮𝐧𝐜𝐭𝐢𝐨𝐧

```plaintext
function functionName([arg1,arg2,...argN]){
//Code to be executed
}
```

𝐄𝐱𝐚𝐦𝐩𝐥𝐞

```javascript
function sayHello(){
    console.log("Hello JavaScript");
}
sayHello();
```

𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐰𝐢𝐭𝐡 𝐀𝐫𝐠𝐮𝐦𝐞𝐧𝐭𝐬

Function can be called through passing the arguments.following is the example of function with arguments.

```javascript
function addition(num){
    let value = num + num;
    console.log(value);
}

addition(4);
```

𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐰𝐢𝐭𝐡 𝐫𝐞𝐭𝐮𝐫𝐧 𝐯𝐚𝐥𝐮𝐞

Whenever we call a function it returns the value which can be used in the program.

```javascript
function square(num){
    let value = num*num;
    return value;
}

console.log(square(4));
```

𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐢𝐧 𝐯𝐚𝐫𝐢𝐚𝐛𝐥𝐞

function can be assigned to the variable.following is the example of it.

```javascript
var square = function(num){
        let value = num*num;
        return value;
}

console.log(square(4));
```

𝐀𝐫𝐫𝐨𝐰 𝐟𝐮𝐧𝐜𝐭𝐢𝐨𝐧

Arrow function were introduced after ES6,basic example of arrow function is given bellow.

```javascript
var sayHello = ()=>{
    console.log("Say Hello");
}

sayHello();
```
