Function in JavaScript is a block of code, which is designed to perform any particular task. A JavaScript function can be executed by calling or invoking it. The main idea of using function is to put commonly used task together inside a function, so that instead of writing the same code again and again for different inputs, we can call that particular function.
// Defining a function
function functionName() {
Statements;
};
// Calling a function
functionName();
function sayHello() {
console.log("Hello World !");
};
sayHello();