> For the complete documentation index, see [llms.txt](https://v-vishwanath.gitbook.io/kiraak/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://v-vishwanath.gitbook.io/kiraak/fundamentals/functions.md).

# Functions

Function ek mini program jaisa hai jo ek specific kaam ya action karta. Isme hona hai toh inputs deke outputs bhi nikal sakte.

Function ko pehle define karna padta. Jaise pehle [Data Types](/kiraak/fundamentals/data-types.md#function) me bataye, function bhi ek data type jaisa hai jo ek **code block** ko store karta.&#x20;

Ab jo inputs dere apan function ko usko **arguments** boltey hai. Ek function kitte bhi arguments le sakta, lekin ek hi output de sakta hai jisko **return value** boltey hai.

{% code overflow="wrap" %}

```
=> Ye function koi arguments ich nai leta hai aur koi value return bhi nahi deta
greet function boletoh {
    screen pe "Hello world!" dikha
}

=> Ab ye function koi arguments toh nai leta lekin value return karega
greetWithReturn function boletoh {
    greeting boletoh "Hello world"
    greeting dega
}

=> Aise ich ye function ab arguments lega aur koi return value nai deta
add function boletoh a, b lega aur {
    screen pe a + b dikha
}

=> Last me ye vala arguments bhi leta hai aur value return bhi karega
addWithReturn function boletoh a, b lega aur {
    sum boletoh a + b
    sum dega
}

```

{% endcode %}

{% hint style="info" %}
Ab loops aur conditional ke tarah function ka apna kudh ka scope hota hai. Ab ek line ka function hai toh usey bina scope banaye likh sakte, lekin phir bhi function apne kudh ke scope me ich kaam karta:

`add function boletoh a, b lega aur a + b dega`

Jaisa ich function chalna bandh hojata, vaise ich sab ke sab variables delete!
{% endhint %}

Ab ye code tab tak nai chalta jab tak hamloga isko nai chalate. Isiko doosre programming languages me **function call** boltey hai:

```
=> function ko seedha chala sakte
greet ko chala

=> Agar arguments dena ho toh vo bhi de sakte
x boletoh 10 hai
add function ko x, x + 10 deke chala

=> Ab return value ko variable me bhi daalke rakh sakte
sum boletoh addWithReturn function ko x, x + 10 deke chala

=> Agar kisi function koi return nai deta tab variable khaali hoga
value boletoh greet function ko chala
value khaali hai => sahi

```
