---
title: "Discussion on \"Why use functions?\" | Hashnode"
description: "Discussion on \"Why use functions?\". You could write your whole JavaScript script in one long thing. The advantage of is that you read it from top to bottom. And if you only have a few lines of code, that isn't going to be a problem. But if you have 400 lines of code, then it gets trick..."
url: "https://hashnode.com/posts/why-use-functions/603136f372a689446db3df14"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Why use functions?](https://blog.nicm42.me.uk/why-use-functions?utm_source=hashnode&utm_medium=feed)

You could write your whole JavaScript script in one long thing. The advantage of is that you read it from top to bottom. And if you only have a few lines of code, that isn't going to be a problem. But if you have 400 lines of code, then it gets trick...

Feb 20, 2021 · 3 min read · blog.nicm42.me.uk  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Nic](https://hashnode.com/@nicm42)

@nicm42 · England

  
[View profile](https://hashnode.com/@nicm42)

This week I learnt...

Front End Developer. I like problem solving and making things pretty. I also like red.

## Responses 1

Markdown supported · ⌘↵ to post

[Purvi Barot](https://hashnode.com/@purvi)

[Feb 25, 2021](https://hashnode.com/posts/why-use-functions/603136f372a689446db3df14/comment/603734bc05efef7f0a9d4507)

A function is a group of statements that together perform a specific task. You can write all intended functionality at one place and call it wherever required.

**Why use function ?**

Function are used for divide a large code into module, due to this we can easily debug and maintain the code. For example if we write a calculator programs at that time we can write every logic in a separate function (For addition sum(), for subtraction sub()). Any function can be called many times.

**Defining a function:**

```
return_type  function_name(parameter) 
{ 
function body; 
}
```

**Calling a function:**

```
function_name();  
OR   
variable=function_name(argument);
```

**Advantage of Function:**

-   Code Re-usability
-   Develop an application in module format.
-   Easily to debug the program.
-   Code optimization: No need to write lot of code.
-   Length of the source code can be reduced.
