function expression and declaration code example
Example 1: function expression
const getRectArea = function(width, height) {
return width * height;
};
console.log(getRectArea(3, 4));
// expected output: 12
Example 2: javascript function expression
const mul = function(x, y){
return x * y;
}; //semicolon needs to be there as it is expression
console.log(mul(10, 20));
Example 3: function expression and function declaration
// Function Declaration
function add(a, b) {
return a + b;
}
console.log(add(1,2)); //3
// Function Expression
const add = function (a, b) {
return a + b;
};
console.log(add(1,2)); //3