About Lesson
Function Declaration vs Function Expression
1. Function Declaration:
Declares a function with a name and can be called before its definition (because of hoisting).
Example:
JavaScript
function greet(name) {
return "Hello " + name;
}
console.log(greet("Manjeet"));
2. Function Expression:
A function can also be assigned to a variable. In this case, it’s called a function expression.
Example:
JavaScript
const greet = function(name) {
return "Hello " + name;
};
console.log(greet("Manjeet"));