Advertisement
Google Ad Slot: content-top
JS Functions
A function in JavaScript is a reusable block of code designed to perform a specific task. Functions make code modular, readable, and reusable.
Syntax:
function functionName(parameters) {
// Function body
return value;
}
Function Declaration:
A function declaration defines a named function using the function keyword.
Function Expression:
A function expression assigns a function to a variable.
Syntax:
const functionName = function(parameters) {
// Function body
return value;
}
Arrow Functions (ES6):
Arrow functions provide a shorter syntax and automatically bind this.
Syntax:
const functionName = (parameters) => {
// Function body
};
Immediately Invoked Function Expressions (IIFE):
An IIFE runs immediately after being defined.