Function Declaration
Defining functions with the function keyword.
Examples
Basic Declaration
A simple function that takes a name and returns a greeting.
function greet(name) {
return "Hello " + name;
}
console.log(greet("Alice"));Hoisting Example
Function declarations are hoisted to the top of their scope.
console.log(square(5)); // Works, output: 25
function square(n) {
return n * n;
}Test Your Knowledge
JavaScript Quiz
No quiz available for this topic yet.