JavaScript function
JavaScript function
The function statement is used for declaring a function. Its main purpose is for reusability. Without it, we have to write the same code multiple times for different inputs. Therefore, we can say that a function is saved for later use. When it is invoked, it will be executed. In JavaScript, functions include properties and methods and therefore are objects.
Syntax:-
Its syntax is:-
function functionName(parameters) {
// code to be executed
}
Further Explanation:-
Parameter | Description |
functionName | Required. The name of the function. Rules are the same as JavaScript variables. |
parameters | Optional. A set of arguments/parameter names, separated by commas. |