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 function way 1
syntax :
function square(number) {
return number * number;
}
// defining function way 2
syntax :
const square = function (number) {
return number * number;
}
// calling function
syntax :
square (5) ;
// calling function
syntax :
let sum_array = (array) => {
sum = 0;
for (let x =0; x<=5;x++) {
sum = sum + array[x] ;
}
return sum