DEV Community

Cover image for What is JavaScript Function?
Abhishek Shukla
Abhishek Shukla

Posted on

What is JavaScript Function?

After reading the title you must want to know what is Function and how it is used in javaScript. So let's talk about it.

1.Functions.

So, Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure a set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it. If you want to learn deep about the function click (here).

2. How to define Functions.

Here you can know that how you can define a function first of all define function is also called a Function declaration, or Function statement. consists of the function keyword, followed by:

1.The name of the function.
2.A list of parameters to the function, enclosed in parentheses and separated by commas.
3.The JavaScript statements that define the function, enclosed in curly brackets, {...}.

For example:-
function square(number){
return number*number;
};

This code defines the simple function (square).
The function square takes one parameter, called number. The function consists of one statement that says to return the parameter of the function (that is, number) multiplied by itself. The statement return specifies the value returned by the function:

Top comments (0)