Minds
It is Recommended to practice while you learn

Functions

Functions are one of the fundamental building blocks in JavaScript. A function in JavaScript is similar to a procedure—a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output. To use a function, you must define it somewhere in the scope from which you wish to call it.

Defining functions


// defining function way 1

syntax :

function square(number) {
return number * number;
}

// defining function way 2

syntax :

const square = function (number) {
return number * number;
}

calling functions


// calling function

syntax :

square (5) ;

Arrow functions


// calling function

syntax :

let sum_array = (array) => {

sum = 0;

for (let x =0; x<=5;x++) {
sum = sum + array[x] ;
}
return sum