Functions in javascript

What is a Function?

A function is a block of code designed to perform a specific task.
It runs only when it is called.

function add() {
console.log("Hello, World!");
}
add();

** Function Expression**

A function can also be stored in a variable.

const multiply = function(a, b) {
return a * b;
};
console.log(multiply(4, 2));

*Arrow Functions *

Arrow functions provide a shorter syntax.

const subtract = (a, b) => a - b;
console.log(subtract(10, 4));

Leave a Reply