Technical Blog
JS Fundamentals
Learning Competencies


What are JavaScript Functions?

A JavaScript function is a procedure or a subprogram, i.e., a block of code that performs a certain task. It is a group of reusable code that you can use anywhere in the code. It helps you to divide a large program into small and manageable functions. With the help of functions, you don’t need to write the same block of code repeatedly. This makes a program a lot more efficient and reduces the code length.


We used some functions like prompt() and write() in our previous JavaScript Tutorials of this series. These are the built-in functions that JavaScript provides, and you will learn more about them later in this tutorial. For now, let’s move onto the syntax of a JavaScript function.

Function Definition

A function definition (also called a function statement or a function declaration) includes a function keyword, with its syntax as follows:

function



The basic idea of a function is to reduce the number of repeated code blocks and executing a code block whenever needed.



>