function declaration and function expression code example
Example 1: function expression vs function declaration
const functionExpression = function(width, height) {
return width * height;
};
console.log(functionExpression(3, 4));
function functionDeclaration(width,height){
return width * height;
};
console.log(functionDeclaration(3,4));
Example 2: js function expression
const plantNeedsWater = function(day){
if (day === 'Wednesday'){
return true;
} else{
return false;
}
}
console.log(plantNeedsWater('Tuesday'))
Example 3: function expression
const getRectArea = function(width, height) {
return width * height;
};
console.log(getRectArea(3, 4));
Example 4: function expression and function declaration
function add(a, b) {
return a + b;
}
console.log(add(1,2));
const add = function (a, b) {
return a + b;
};
console.log(add(1,2));