Chapter VI · Functions
Function Declaration
A function declaration defines a named function and is fully hoisted during compilation.
01 How It Works
Think of an official announcement registered before the event begins.
Declarations are moved to the top of their scope, allowing invocation before the definition line.
example.js
sayHi();
function sayHi() {
console.log("Hi!");
}
1. Write the function keyword.
2. Provide a function name.
3. Define parameters and block body.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
function add(a, b) {
return a + b;
}
Key Takeaway
Function declarations are hoisted, making them available everywhere in scope.