Function Declaration
A function declaration defines a named function using the function keyword.
This function is hoisted to the top of its scope, meaning it can be called
before it is defined in the code.
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet('Alice'));
Function Expression
A function expression defines a function as part of a larger expression,
typically assigning it to a variable. Unlike function declarations,
function expressions are not hoisted, so they cannot
be called before they are defined.
const greet = function(name) {
return `Hello, ${name}!`;
};
console.log(greet('Alice'));