ScanSkill

function

A function is a statement, it can be given its own set of parameters. It is a block of code that is made to do a batch type of operation or group of similar operations.

Syntax

function name(param, ...) {
  // Statements
}

The function statement is used to group code into a block, it may take in parameters, and it may return something back.

Example

function addNumbers(a, b) {
	return a + b;
}

console.log(addNumbers(10, 20)); // Returns: 30

The function keyword is used to group similar code, and it is called by invoking its name with small brackets i.e. name(). If the function has a return statement it returns the required value, if it doesn’t then the code returns nothing and continues normally.