JavaScript Functions
Functions are reusable blocks of code. They help with organization, encapsulation, and reducing repetition.
Function Declaration (Named Function):
function greet(name) { // Function definition
return `Hello, ${name}!`; // Function body
}
console.log(greet("Alice")); // Function call
Function expression:
const multiply = function(a, b) {
return a * b;
};
console.log(multiply(3, 5)); // Output: 15
Arrow Function (ES6):
const divide = (a, b) => {a / b};
console.log(divide(10, 2)); // Output: 5
Arguments
const sayHello = (name) => {
console.log(`Hello ${name}`);
}