Function
Function is a block of code designed to perform a specific task. It executes only when it is called (invoked).
- Code reusable
- Declare code once,use it whenever we want
- Call the function to execute the code
Syntax
function functionName() {
// Code to execute
}
Example
function ammatea(){
console.log("Unoda Tea Ready");
}
ammatea();
Output:Unoda Tea Ready
Code Reusability
Write the code once and use it multiple times
function add() {
console.log(10 + 20);
}
add();
add();
add();
Modularity
Divide a large program into smaller, manageable parts (modules/functions)
function login() {
console.log("User logged in");
}
function displayProfile() {
console.log("Profile displayed");
}
function logout() {
console.log("User logged out");
}

Top comments (0)