In JavaScript, functions are fundamental building blocks that allow developers to encapsulate a set of statements performing a task or calculating a value. A function must take some input and return an output with some obvious relationship between the two.
Basically, they allow us to write concise, modular, reusable and maintainable code.
Defining a Function
Functions can be defined using the function keyword, followed by a name and a set of parentheses. The function’s code is contained within curly braces.
function greet() {
console.log("Namaste, World!");
}
//To call or invoke this function, you'd use the function name followed by parentheses:
greet(); //Outputs: "Namaste, world"